hdoj 1162 Eddy's picture
并查集+最小生成树
Eddy's picture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7669 Accepted Submission(s):
3882
sure of himself to become a painter.Every day Eddy draws pictures in his small
room, and he usually puts out his newest pictures to let his friends appreciate.
but the result it 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?
of point. For each point, a line follows; each following line contains two real
numbers indicating the (x,y) coordinates of the point.
Input contains
multiple test cases. Process to the end of file.
places: the minimum total length of ink lines that can connect all the points.
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int set[110];
struct record//注意此题要用实型
{
double a;
double b;
double ju;//两点之间距离
}s[10000];
int find(int fa)
{
int ch=fa;
int t;
while(fa!=set[fa])
fa=set[fa];
while(ch!=fa)
{
t=set[fa];
set[ch]=fa;
ch=t;
}
return fa;
}
void mix(int x,int y)
{
int fx,fy;
fx=find(x);
fy=find(y);
if(fx!=fy)
set[fx]=fy;
}
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); //计算两点之间距离
}
bool cmp(record c,record d)
{
return c.ju<d.ju;
}
int main()
{
int m,j,i,point;
double sum;
double a[110];//这两个数组用来储存点的坐标,a数组储存横标
double b[110];//b数组储存纵标
while(scanf("%d",&point)!=EOF)
{
for(i=0;i<=point;i++)
set[i]=i;
for(i=1;i<=point;i++)
{
scanf("%lf%lf",&a[i],&b[i]);
}
m=0;
for(i=1;i<=point-1;i++) //此循环求任意两点之间距离
{ //并记录下此两点位置
for(j=i+1;j<=point;j++)
{
s[m].ju=dis(a[i],b[i],a[j],b[j]);
s[m].a=i;
s[m].b=j;
m++;
}
}
sort(s,s+m,cmp);
sum=0;
for(i=0;i<m;i++)
{
if(find(s[i].a)!=find(s[i].b))
{
mix(s[i].a,s[i].b);
sum+=s[i].ju;
}
}
printf("%.2lf\n",sum);
}
return 0;
}
hdoj 1162 Eddy's picture的更多相关文章
- 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(最小生成树算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- 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
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- 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 (prim)
Eddy's pictureTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1162 Eddy's picture (最小生成树 prim)
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- HDU 1162 Eddy's picture (最小生成树 普里姆 )
题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...
- 题解报告:hdu 1162 Eddy's picture
Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...
随机推荐
- Android SlidingMenu的getSupportActionBar无法找到的解决
getSupportActionBar()方法不能用 进入Library中的src下找到SlidingFragmentActivity.java,修改 public class SlidingFrag ...
- 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...
- [itint5]最大子矩阵和
http://www.itint5.com/oj/#39 最大子矩阵和,复杂度O(n^3).利用了最大子段和的方法. int maxRectSum(vector<vector<int> ...
- jstack(查看线程)、jmap(查看内存)和jstat(性能分析)
公司内部同事分享的一篇文章 周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令.供大家参考 1.Jstack 1.1 ...
- POJ2253——Frogger(Floyd变形)
Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...
- 在Tomcat上配置CAS 自己的体验
演示环境 本文演示过程在同一个机器上的(也可以在三台实体机器或者三个的虚拟机上),环境如下: windows732位 JDK 1.6.0_18 Tomcat 6.0.29 CAS-server-3.4 ...
- Android开发之parseSdkContent failed Could not initialize class android.graphics.Typeface
在进行android开发过程中,忽然发现经常弹出来parseSdkContent failed 这个错误,然后google了下解决办法 方法1: 删除.android文件 重启eclipse. 该方法 ...
- poj 1259 Agri-Net(最小生成树)
题目:http://poj.org/problem?id=1258 题意:模板题 和2485差不多 就是求相连后的最小值. #include <iostream> #include< ...
- Java传参那些事!
刚刚学习java传参的时候很纠结,也非常的不理解!课本上的“按值传递”和“按址传递”搞的自己是一头雾水,后来写的项目多了,自然就明白了! 现在写传参几乎就是条件反射一般——“秒成”,分享当初自己为此写 ...
- Amoeba搞定mysql主从读写分离
前言:一直想找一个工具,能很好的实现mysql主从的读写分离架构,曾经试用过mysql-proxy发现lua用起来很不爽,尤其是不懂lua脚本,突然发现了Amoeba这个项目,试用了下,感觉还不错,写 ...