Eddy's picture
Eddy's picture
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 8 Accepted Submission(s) : 3
can be imagined, the friends are not interested in his picture.Eddy feels very puzzled,in order to change all friends 's view to his technical of painting pictures ,so Eddy creates a problem for the his friends of you.
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?
the end of file.
3
1.0 1.0
2.0 2.0
2.0 4.0
3.41
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int pre[101];
void itin()
{
for(int i=0;i<101;i++)
pre[i]=i;
}
struct point
{
float x,y;
}p[100];
struct dis
{
int u,v;
float val;
}d[100010];
int cmp(dis n1,dis n2)
{
if(n1.val<n2.val)
return 1;
return 0;
}
int find(int x)
{
while(x!=pre[x])
x=pre[x];
return x;
}
bool join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
pre[fx]=fy;
return true;
}
return false;
}
int main()
{
int t;
while(scanf("%d",&t)!=EOF)
{
itin();
int i,j;
memset(p,0,sizeof(p));
float sum=0;
for(i=0;i<t;i++)
scanf("%f%f",&p[i].x,&p[i].y);
int cnt=0;
for(i=0;i<t;i++)
for(j=i+1;j<t;j++)
{
float dist=sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
d[cnt].u=i;
d[cnt].v=j;
d[cnt++].val=dist;
}
sort(d,d+cnt,cmp);
/*for(i=0;i<cnt;i++)
printf("%f ",d[i].val);
printf("\n");*/
for(i=0;i<cnt;i++)
{
if(join(d[i].u,d[i].v))
{
sum+=d[i].val;
//printf("%f\n",sum);
} }
printf("%.2f\n",sum);
}
return 0;
}
Eddy's picture的更多相关文章
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdoj 1162 Eddy's picture
并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- HDU 1162 Eddy's picture
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- Eddy's picture(prime+克鲁斯卡尔)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- hdu Eddy's picture (最小生成树)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- 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 (最小生成树)(java版)
Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...
- 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 ...
- 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 ...
随机推荐
- [hihocoder][Offer收割]编程练习赛50
循环数组 计算a[i]的前缀和s[i],计算l[i]为1~i-1中最小的s值,r[i]为i~n中最大的s值. 则a[i]~a[n]满足性质的条件为r[i]-s[i-1]>0,a[1]~a[i-1 ...
- GO 协程 通道实例以及验证SnowFlake算法
最近项目中使用了SnowFlake算法产生ID,并在实际运行环境下会产生重复ID,所以写了一个Go的程序进行验证,顺便也练习一下Go的协程与通道. 至于GO的协程和通道的基础知识请自行百度. 代码如下 ...
- bootstrap模态框和select2合用时input无法获取焦点(转)
在bootstrap的模态框里使用select2插件,会导致select2里的input输入框没有办法获得焦点,没有办法输入. 解决方法: 1. 把页面中的 tabindex="-1&qu ...
- Css打造一个简单的静态七巧板
偶然在微博上看到用css写一个七巧板,正好也有一些源代码,于是就试着敲了敲. 主要是利用了css3的transform,实现平移,旋转,变形,直接用看到的代码敲出来之后有些问题,因为宽度上下面绿色的三 ...
- 在MFC中使用Cstring
此文介绍了关于MFC使用CString的资料,可一参考一下. 转自于VC知识库:http://www.vckbase.com/index.php/wv/829 通过阅读本文你可以学习如何有效地使用 C ...
- 读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++]
读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++] 第2章 数据和基本类型 1. 整型 2. 习题:左值和右值 3. C++关键字/保留字和操作符替代值 4. 声明 ...
- 【转载】java中的反射
主要介绍以下几方面内容 理解 Class 类 理解 Java 的类加载机制 学会使用 ClassLoader 进行类加载 理解反射的机制 掌握 Constructor.Method.Field 类的用 ...
- python PIL图像处理-生成图片验证码
生成效果如图: 代码 from PIL import Image,ImageDraw,ImageFont,ImageFilter import random # 打开一个jpg图像文件: im = I ...
- shell脚本中source无效
发现在shell里面执行source,提示找不到命令.所以,我取搜了一些资料,总结一下. 一. 脚本中,source找不到命令--------------是因为用了sh执行脚本,而debian系统的s ...
- 常用rides命令
rides使用步骤 1.源代码构建安装 1.下载,Linux下命令wget http://redis.io/download下载redis的包 2.解归档Linux下命令tar -xvf redis- ...