Eddy's picture

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6339    Accepted Submission(s): 3179

Problem Description
Eddy begins to like painting pictures recently ,he is 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?
 
Input
The first line contains 0 < n <= 100, the number 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.

 
Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points. 
 
Sample Input
3
1.0 1.0
2.0 2.0
2.0 4.0
 
Sample Output
3.41
 
Author
eddy
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1301 1213 1116 1269 1198 
 

最小生成树入门题:

  1. //0MS 384K 1215B G++
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5. struct point{
  6. double x,y;
  7. }p[];
  8. struct node{
  9. int u,v;
  10. double d;
  11. }t[];
  12. int set[],n;
  13. int cmp(const void*a,const void*b)
  14. {
  15. return (*(node*)a).d>(*(node*)b).d?:-;
  16. }
  17. int find(int x)
  18. {
  19. if(set[x]!=x) set[x]=find(set[x]);
  20. return set[x];
  21. }
  22. int merge(int a,int b)
  23. {
  24. int x=find(a);
  25. int y=find(b);
  26. if(x!=y){
  27. set[x]=y;
  28. return ;
  29. }
  30. return ;
  31. }
  32. double kruskal()
  33. {
  34. double ans=;
  35. for(int i=;i<n*n;i++)
  36. if(merge(t[i].u,t[i].v))
  37. ans+=t[i].d;
  38. return ans;
  39. }
  40. double dis(point a,point b)
  41. {
  42. return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  43. }
  44. int main(void)
  45. {
  46. while(scanf("%d",&n)!=EOF)
  47. {
  48. for(int i=;i<=n;i++) set[i]=i;
  49. for(int i=;i<n;i++)
  50. scanf("%lf%lf",&p[i].x,&p[i].y);
  51. int k=;
  52. for(int i=;i<n;i++)
  53. for(int j=;j<n;j++){
  54. t[k].u=i;
  55. t[k].v=j;
  56. t[k].d=dis(p[i],p[j]);
  57. k++;
  58. }
  59. qsort(t,n*n,sizeof(t[]),cmp);
  60. printf("%.2lf\n",kruskal());
  61. }
  62. return ;
  63. }

hdu 1162 Eddy's picture (最小生成树)的更多相关文章

  1. hdu 1162 Eddy's picture(最小生成树算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...

  2. HDU 1162 Eddy's picture (最小生成树)(java版)

    Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...

  3. 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 ...

  4. HDU 1162 Eddy's picture

    坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32 ...

  5. hdu 1162 Eddy's picture (prim)

    Eddy's pictureTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. HDU 1162 Eddy's picture (最小生成树 prim)

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  7. HDU 1162 Eddy's picture (最小生成树 普里姆 )

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  8. hdu 1162 Eddy's picture(最小生成树,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...

  9. 题解报告:hdu 1162 Eddy's picture

    Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...

随机推荐

  1. Unknown host 'services.gradle.org' 解决方法

    报错如下: Unknown host 'services.gradle.org'. You may need to adjust the proxy settings in Gradle. Learn ...

  2. 「日常训练」Balancing Act(POJ-1655)

    题意与分析 树的重心板子题. 值得考虑的是,重心究竟有哪些优秀的性质? 这里是一些网上能看到的性质: (判定性质)找到一个点,其所有的子树中最大的子树节点数最少(子树可以"倒着看" ...

  3. 【转】Unity 使用xLua遇到的坑

    在我们使用xLua作为Unity中lua集成的解决方案时,遇到了一个问题,就是当我们使用在lua中把UI中的某个控件绑定相应的事件(如按钮的onClick事件),xLua绑定这个事件是用委托实现的,具 ...

  4. IDEA搭载Tomcat使用JSTL连接Oracle数据库

    1.在IDEA中,JSTL库添加到WEB-INF/lib下面可以直接在JSP页面上通过 <%@ taglib uri="http://java.sun.com/jsp/jstl/cor ...

  5. Matlab提速方法

    1. 向量化. 尽量少用for循环. 2. 循环竖着走比横着走快. 3. 内置函数也有优化的空间 不少内置函数都有大量的error check.直接用profiler找出真正干活的.不少内置函数在网上 ...

  6. Python3 数值类型与运算符

    1.数值类型与进制 (1)基本类型 整型:int 浮点型:float 布尔类型:bool 复数:complex print(type(1)) print(type(1.1)) print(type(F ...

  7. es6从零学习(四):Class的继承

    es6从零学习(四):Class的继承 一:继承的方式 1.Class 可以通过extends关键字实现继承 class Point { } class ColorPoint extends Poin ...

  8. Python中__name__属性的妙用

    在Python中,每一个module文件都有一个built-in属性:__name__,这个__name__有如下特点: 1 如果这个module文件是被别的文件导入的,那么,该__name__属性的 ...

  9. 如果Python对于磁盘没有写入权限,还会运行吗?

    Python如果对于磁盘没有写入权限,那么编译成功的字节码文件就只会存储在内存当中,而不会写入到磁盘,每次运行Python都会重新编译,然后运行.

  10. 最短路径——Dijkstra(简易版)

    简易之处:顶点无序号,只能默认手动输入0,1,2...(没有灵活性) #include <iostream> #include <cstdio> #include <cs ...