Eddy's picture

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 3
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
  1. 3
  2. 1.0 1.0
  3. 2.0 2.0
  4. 2.0 4.0
  5.  
 
Sample Output
  1. 3.41
  2.  
 
Author
eddy
 
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<algorithm>
  5. using namespace std;
  6. int pre[101];
  7. void itin()
  8. {
  9. for(int i=0;i<101;i++)
  10. pre[i]=i;
  11. }
  12. struct point
  13. {
  14. float x,y;
  15. }p[100];
  16. struct dis
  17. {
  18. int u,v;
  19. float val;
  20. }d[100010];
  21. int cmp(dis n1,dis n2)
  22. {
  23. if(n1.val<n2.val)
  24. return 1;
  25. return 0;
  26. }
  27. int find(int x)
  28. {
  29. while(x!=pre[x])
  30. x=pre[x];
  31. return x;
  32. }
  33. bool join(int x,int y)
  34. {
  35. int fx=find(x);
  36. int fy=find(y);
  37. if(fx!=fy)
  38. {
  39. pre[fx]=fy;
  40. return true;
  41. }
  42. return false;
  43. }
  44. int main()
  45. {
  46. int t;
  47. while(scanf("%d",&t)!=EOF)
  48. {
  49. itin();
  50. int i,j;
  51. memset(p,0,sizeof(p));
  52. float sum=0;
  53. for(i=0;i<t;i++)
  54. scanf("%f%f",&p[i].x,&p[i].y);
  55. int cnt=0;
  56. for(i=0;i<t;i++)
  57. for(j=i+1;j<t;j++)
  58. {
  59. 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));
  60. d[cnt].u=i;
  61. d[cnt].v=j;
  62. d[cnt++].val=dist;
  63. }
  64. sort(d,d+cnt,cmp);
  65. /*for(i=0;i<cnt;i++)
  66. printf("%f ",d[i].val);
  67. printf("\n");*/
  68. for(i=0;i<cnt;i++)
  69. {
  70. if(join(d[i].u,d[i].v))
  71. {
  72. sum+=d[i].val;
  73. //printf("%f\n",sum);
  74. }
  75.  
  76. }
  77. printf("%.2f\n",sum);
  78. }
  79. return 0;
  80. }

Eddy's picture的更多相关文章

  1. HDUOJ-----(1162)Eddy's picture(最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. hdoj 1162 Eddy's picture

    并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  3. HDU 1162 Eddy's picture

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

  4. Eddy's picture(prime+克鲁斯卡尔)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  5. hdu Eddy's picture (最小生成树)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

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

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...

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

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

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

  9. hdu 1162 Eddy's picture (最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

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

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

随机推荐

  1. jQuery学习笔记之jQuery的Ajax(3)

    jQuery学习笔记之jQuery的Ajax(3) 6.jQuery的Ajax插件 源码地址: https://github.com/iyun/jQueryDemo.git ------------- ...

  2. Android java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader......couldn't find "libweibosdkcore.so

    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ ...

  3. sql server 还原数据库,数据库提示正在还原中的处理办法

      还原数据库时,提示还原成功,可是数据库列表中该数据库显示正在还原中: 执行此命令即可: RESTORE DATABASE EnterPriseBuilding WITH RECOVERY 了解SQ ...

  4. JavaScript编程题(一)

    使用Javascript脚板输出如图所示的效果页面: 使用document.write()输出水平线 使用循环控制每个水平线的长度 答案:<!doctype html> <html ...

  5. std::string格式化输入输出

    在C语言中: C函数有sprintf函数, 比较方便, 但是需要知道所需要的内存空间是多少. 在C++的框架MFC中: 在MFC中CString 有Format函数来格式化字符串. 很方便. 难过的是 ...

  6. EMC VNX5200/5400存储 新增LUN与Hosts映射操作

    EMC VNX5200/5400 1.创建RAID  Groups 1.1        进入EMC VNX5200/5400主界面,依次选择Storage——Storage Pools——RAID ...

  7. 自定义View实现拖动小圆球,并随机改变其颜色

    //简单实现package com.example.demo1; import android.content.Context;import android.graphics.Canvas;impor ...

  8. 爬虫系列(八) 用requests实现天气查询

    这篇文章我们将使用 requests 调用天气查询接口,实现一个天气查询的小模块,下面先贴上最终的效果图 1.接口分析 虽然现在网络上有很多免费的天气查询接口,但是有很多网站都是需要注册登陆的,过程比 ...

  9. 30.es增删改内部分发原理

    当客户端发送一次请求时,大致会经过以下几个步骤     (1)客户端发送一个请求过去,es的一个node接收到这个请求(随机的),这个node就被es内部分配成coordinating node(协调 ...

  10. SQLServer · BUG分析 · Agent 链接泄露分析(转载)

    背景 SQLServer Agent作为Windows服务提供给用户定期执行管理任务,这些任务被称为Job:考虑应用镜像的场景如何解决Job同步问题,AWS RDS的做法是不予理会,由用户维护Job, ...