hdu Eddy's picture (最小生成树)
Eddy's picture
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 29 Accepted Submission(s) : 26
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Problem descriptions as follows: Given you some coordinates pionts on a drawing paper, every point links with the ink with the straight line, causes all points finally to link in the same place. How many distants does your duty discover the shortest length which the ink draws?
Input
Input contains multiple test cases. Process to the end of file.
Output
Sample Input
3
1.0 1.0
2.0 2.0
2.0 4.0
Sample Output
3.41
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
using namespace std;
const int maxn=;
double mp[maxn][maxn];
double dis[maxn],x[maxn],y[maxn];
int vis[maxn];
int i,j,n,l,k;
double minn,sum; int main()
{
while(~scanf("%d",&n))
{
memset(vis,,sizeof(vis));
for(i=;i<=n;i++) scanf("%lf%lf",&x[i],&y[i]);
for(i=;i<=n;i++)
for(j=i+;j<=n;j++)
{
double d=sqrt(pow(x[i]-x[j],)+pow(y[i]-y[j],));
mp[i][j]=d;
mp[j][i]=d;
}
sum=;
vis[]=;
for(i=;i<=n;i++) dis[i]=mp[][i];
for(i=;i<n;i++)
{
minn=INT_MAX*1.0;
for(j=;j<=n;j++)
if(!vis[j] && minn>dis[j])
{
k=j;
minn=dis[j];
}
vis[k]=;
sum+=minn;
for(j=;j<=n;j++)
if (!vis[j] && dis[j]>mp[k][j])
dis[j]=mp[k][j];
}
printf("%.2lf\n",sum);
}
return ;
}
hdu Eddy's picture (最小生成树)的更多相关文章
- HDU 1162 Eddy's picture (最小生成树)(java版)
Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...
- hdu 1162 Eddy's picture (最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1162 Eddy's picture(最小生成树算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1162 Eddy's picture (Kruskal 算法)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1162 Eddy's picture
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- hdu 1162 Eddy's picture (prim)
Eddy's pictureTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdoj 1162 Eddy's picture
并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
随机推荐
- [ An Ac a Day ^_^ ] UVALive 7270 Osu! Master
2015icpc北京区域赛的签到题 还是很签到的 一次就过了 题意呢 就是统计B C后最长上升序列还有S的个数 当然B C要被S分割开…… /* *************************** ...
- 经典dp 最长公共子序列
首先,说明一下子序列的定义…… 一个序列A={a1,a2,a3,...,an},从中删除任意若干项,剩余的序列叫A的一个子序列. 很明显(并不明显……),子序列……并不需要元素是连续的……(一开始的时 ...
- There was a problem parsing the package(android)
android phone when you install the application there will inevitably be "a problem parsing the ...
- AFNetWoring导入报错解决方案
第一个当报cannot find interface declaration for 'UIImage或者use of undeclared identifier 'UIImage'时我们要在报错页面 ...
- UI----安健2 UIswitch UIslider
- (void)viewDidLoad { [super viewDidLoad]; [self buttonswitch]; [self buttonslider]; } -(void)button ...
- vs中的各种快捷键
1. VS注释与取消注释快捷键 CTRL + K , CTRL + C(注释) CTRL + K , CTRL + U(取消注释)
- tableView左滑按钮
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsFo ...
- 8. Python自定义模块humansize
我们在提取一个文件元信息的时候,经常会使用到获取元信息的size, 但是默认提取出来的是字节为单位计算的大小,我们需要转换成MB或者GB 或者TB的大小. 因此就需要使用到humansize这个模块, ...
- HDU - 5455 Fang Fang
Problem Description Fang Fang says she wants to be remembered.I promise her. We define the sequence ...
- maven依赖本地宝
http://www.mamicode.com/info-detail-169419.html 引用本地的jar包