1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <cmath>
  5. using namespace std;
  6. typedef struct
  7. {
  8. int a,b;
  9. double v;
  10. }node;
  11. typedef struct
  12. {
  13. int a,b;
  14. }P;
  15. const int maxn=;
  16. double ans;
  17. int father[maxn];
  18. node graph[maxn*(maxn-)/];
  19. P p[maxn];
  20. int Find(int x)
  21. {
  22. if(father[x]==x)
  23. return x;
  24. else
  25. {
  26. father[x]=Find(father[x]);
  27. return father[x];
  28. }
  29. }
  30. void Union(int x,int y,double v)
  31. {
  32. if(Find(x)!=Find(y))
  33. {
  34. ans+=v*;
  35. father[Find(x)]=Find(y);
  36. }
  37. return;
  38. }
  39. bool cmp(node x,node y)
  40. {
  41. if(x.v<y.v)
  42. return true;
  43. else
  44. return false;
  45. }
  46. int main()
  47. {
  48. double V;
  49. int n;
  50. scanf("%d",&n);
  51. while(n--)
  52. {
  53. ans=;
  54. for(int i=;i<maxn;i++)
  55. father[i]=i;
  56. int m,k;
  57. k=;
  58. scanf("%d",&m);
  59. for(int i=;i<m;i++)
  60. {
  61. scanf("%d%d",&p[i].a,&p[i].b);
  62. }
  63. for(int i=;i<m-;i++)
  64. {
  65. for(int j=i+;j<m;j++)
  66. {
  67. V=sqrt(pow((p[i].a-p[j].a),2.0)+pow((p[i].b-p[j].b),2.0));
  68. if(V<=&&V>=)
  69. {
  70. graph[k].a=i;
  71. graph[k].b=j;
  72. graph[k].v=V;
  73. k++;
  74. }
  75. }
  76. }
  77. sort(graph,graph+k,cmp);
  78. for(int i=;i<k;i++)
  79. Union(graph[i].a,graph[i].b,graph[i].v);
  80. int xx=Find();
  81. int flag;
  82. flag=;
  83. for(int i=;i<m;i++)
  84. {
  85. if(Find(i)!=xx)
  86. {
  87. flag=;
  88. break;
  89. }
  90. }
  91. if(flag==)
  92. printf("oh!\n");
  93. else
  94. printf("%.1lf\n",ans);
  95. }
  96. return ;
  97. }
  98.  

HDU 1875(最小生成树)的更多相关文章

  1. hdu 1875 最小生成树 prime版

    最小生成树prime版 大致的步骤 首先选取一个到集合最近的点 然后标记起在集合内部 然后更新最短距离 畅通工程再续 Time Limit: 2000/1000 MS (Java/Others)    ...

  2. HDU 1875 最小生成树prim算法

    #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #inc ...

  3. HDU 1875 畅通工程再续 (prim最小生成树)

    B - 畅通工程再续 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  4. HDU 1875 畅通工程再续 (Prim)

    题目链接:HDU 1875 Problem Description 相信大家都听说一个"百岛湖"的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现 ...

  5. hdu 1875 畅通project再续

    链接:hdu 1875 输入n个岛的坐标,已知修桥100元/米,若能n个岛连通.输出最小费用,否则输出"oh!" 限制条件:2个小岛之间的距离不能小于10米,也不能大于1000米 ...

  6. HDU 1233(最小生成树)

    HDU 1233(最小生成树 模板) #include <iostream> #include <algorithm> #include <cstdio> usin ...

  7. hdu 1875 畅通工程再续(prim方法求得最小生成树)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1875 /************************************************* ...

  8. (最小生成树) 畅通工程再续 -- HDU --1875

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1875 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  9. HDU 1875 畅通工程再续 (最小生成树)

    畅通工程再续 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/M Description 相信大家都听说一个"百岛湖&q ...

随机推荐

  1. Linux随笔-鸟哥Linux基础篇学习总结(全)

    Linux随笔-鸟哥Linux基础篇学习总结(全) 修改Linux系统语系:LANG-en_US,如果我们想让系统默认的语系变成英文的话我们可以修改系统配置文件:/etc/sysconfig/i18n ...

  2. Android wifi 从连接态自动断开的解决办法(dhcp导致)【转】

    本文转载自:http://blog.csdn.net/DKBDKBDKB/article/details/38490201 对wifi部分的代码流程已经看了段时间,前两天终于解决了工作中遇到的一个wi ...

  3. Educational Codeforces Round 2 C. Make Palindrome —— 贪心 + 回文串

    题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds me ...

  4. 使用libcurl进行HTTP GET操作

    Working example how to do a GET request with libcurl and save it to a string variable for future use ...

  5. codeforces B. Roma and Changing Signs 解题报告

    题目链接:http://codeforces.com/problemset/problem/262/B 题目意思:给出 n 个数和恰好一共要做的操作总数k.通过对n个数进行k次操作,每次操作可以把a[ ...

  6. js事件传播的一个疑惑

    在学习事件传播的时候,发现一个问题,当时是这样子的. 我给多层元素分别绑定了冒泡和捕获事件.按道理应该先从外向内执行完所有的捕获事件,再由内向外执行所有的冒泡事件. 但是天不随人愿啊,有个元素偏偏先执 ...

  7. AC自动机-题目集合

    AC自动机-题目集合 模板 如果你想要学习AC自动机,推荐一些学习资料. 学习可以看这篇博客 http://blog.csdn.net/niushuai666/article/details/7002 ...

  8. 51nod最长递增路径:(还不错的图)

    一个无向图,可能有自环,有重边,每条边有一个边权.你可以从任何点出发,任何点结束,可以经过同一个点任意次.但是不能经过同一条边2次,并且你走过的路必须满足所有边的权值严格单调递增,求最长能经过多少条边 ...

  9. FTP:文件传输协议(指令及响应代码)

    文件传输协议(FTP)使得主机间可以共享文件. FTP 使用 TCP 生成一个虚拟连接用于控制信息,然后再生成一个单独的 TCP 连接用于数据传输.控制连接使用类似 TELNET 协议在主机间交换命令 ...

  10. linq Foreach

    lst.ForEach(item => { CbxDF1VersionItemSource.Add(item); });