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 ...
随机推荐
- https 结合使用 对称加密和非对称加密
(一)对称加密(Symmetric Cryptography) ---共享密钥加密 对称加密是最快速.最简单的一种加密方式,加密(encryption)与解密(decryption)用的是同样的密钥( ...
- C# 7.0新加特性
以下将是 C# 7.0 中所有计划的语言特性的描述.随着 Visual Studio “15” Preview 4 版本的发布,这些特性中的大部分将活跃起来.现在是时候来展示这些特性,你也告诉借此告诉 ...
- MVC5+EasyUI+EF6+Linq通用权限系统出炉--登录(2)
1.输入验证码后 自动识别验证码并登录.
- (转)基于Metronic的Bootstrap开发框架经验总结(9)--实现Web页面内容的打印预览和保存操作
http://www.cnblogs.com/wuhuacong/p/5147368.html 在前面介绍了很多篇相关的<Bootstrap开发框架>的系列文章,这些内容基本上覆盖到了我这 ...
- <转>c++引用与指针的区别(着重理解)
★ 相同点: 1. 都是地址的概念: 指针指向一块内存,它的内容是所指内存的地址:引用是某块内存的别名. ★ 区别: 1. 指针是一个实体,而引用仅是个别名: 2. 引用使用时无需解引用(*),指 ...
- Luogu P1365 WJMZBMR打osu! / Easy
概率期望专题首杀-- 毒瘤dp 首先根据数据范围推断出复杂度在O(n)左右 但不管怎么想都是n^2-- 晚上躺在床上吃东西的时候(误)想到之前有几道dp题是通过前缀和优化的 而期望的可加性又似乎为此创 ...
- JavaScript中原生事件
DOM0事件模型: 所有浏览器都支持,只能注册一种事件 1.绑定: document.getElementById("id").onclick = function(e){}; 解 ...
- PAT_A1155#Heap Paths
Source: PAT A1155 Heap Paths (30 分) Description: In computer science, a heap is a specialized tree-b ...
- python jieba分词(添加停用词,用户字典 取词频
中文分词一般使用jieba分词 1.安装 pip install jieba 2.大致了解jieba分词 包括jieba分词的3种模式 全模式 import jieba seg_list = jieb ...
- Layui 行点击追加元素效果
/** * 单击事件 * @param obj */var dom;var state;WarningIllegalIntime.onRowClick=function(obj) { console. ...