1. /*
  2. The first line of each test case contains 1 <= S <= 100, the number of satellite channels!
  3. 注意:S表示一共有多少个卫星,那么就是有 最多有S-1个通道! 然后将最小生成树中的后边的 S-1通道去掉就行了!
  4. 思路:最小生成树中的第 k 个最小边!
  5. */
  6. //克鲁斯克尔算法.....
  7. #include<iostream>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<algorithm>
  11. #include<cmath>
  12. using namespace std;
  13.  
  14. double x[], y[];
  15.  
  16. struct node{
  17. int u, v;
  18. double d;
  19. };
  20.  
  21. bool cmp(node a, node b){
  22. return a.d < b.d;
  23. }
  24.  
  25. int f[];
  26.  
  27. node nd[];
  28. double ret[];
  29.  
  30. int getFather(int x){
  31. return x==f[x] ? x : f[x]=getFather(f[x]);
  32. }
  33.  
  34. bool Union(int a, int b){
  35. int fa=getFather(a), fb=getFather(b);
  36. if(fa!=fb){
  37. f[fa]=fb;
  38. return true;
  39. }
  40. return false;
  41. }
  42.  
  43. int main(){
  44. int n, m;
  45. int t;
  46. scanf("%d", &t);
  47. while(t--){
  48. scanf("%d%d", &m, &n);
  49. for(int i=; i<=n; ++i){
  50. scanf("%lf%lf", &x[i], &y[i]);
  51. f[i]=i;
  52. }
  53. int cnt=;
  54. for(int i=; i<n; ++i)
  55. for(int j=i+; j<=n; ++j){
  56. nd[cnt].u=i;
  57. nd[cnt].v=j;
  58. nd[cnt++].d=sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
  59. }
  60. sort(nd, nd+cnt, cmp);
  61. int cc=;
  62. for(int i=; i<cnt; ++i)
  63. if(Union(nd[i].u, nd[i].v))
  64. ret[cc++]=nd[i].d;
  65. for(int i=; i<cc; ++i)
  66. cout<<ret[i]<<"fdsf"<<endl;
  67. printf("%.2lf\n", ret[n-m-]);
  68. }
  69. return ;
  70. }
  1. //prim算法.......
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<cmath>
  7. using namespace std;
  8. const double INF = 0x3f3f3f3f*1.0;
  9. double x[], y[];
  10.  
  11. int n, m;
  12. double map[][];
  13. int vis[];
  14.  
  15. double ret[];
  16.  
  17. void prim(){
  18. memset(vis, , sizeof(vis));
  19. vis[]=;
  20. for(int i=; i<=n; ++i)
  21. ret[i]=INF;
  22. int root=, p;
  23. for(int i=; i<n; ++i){
  24. double minLen=INF;
  25. for(int j=; j<=n; ++j){
  26. if(!vis[j] && ret[j]>map[root][j])
  27. ret[j]=map[root][j];
  28. if(!vis[j] && minLen>ret[j]){
  29. minLen=ret[j];
  30. p=j;
  31. }
  32. }
  33. root=p;
  34. vis[root]=;
  35. }
  36. }
  37.  
  38. int main(){
  39.  
  40. int t;
  41. scanf("%d", &t);
  42. while(t--){
  43. scanf("%d%d", &m, &n);
  44. for(int i=; i<=n; ++i)
  45. scanf("%lf%lf", &x[i], &y[i]);
  46. for(int i=; i<n; ++i)
  47. for(int j=i+; j<=n; ++j)
  48. map[i][j]=map[j][i]=sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
  49.  
  50. prim();
  51. sort(ret, ret+n+);
  52.  
  53. printf("%.2lf\n", ret[n-m+]);
  54. }
  55. return ;
  56. }

UvaOJ10369 - Arctic Network的更多相关文章

  1. [poj2349]Arctic Network(最小生成树+贪心)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17758   Accepted: 5646 D ...

  2. Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9557   Accepted: 3187 De ...

  3. POJ 2349 Arctic Network (最小生成树)

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  4. POJ 2349 Arctic Network (最小生成树)

    Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...

  5. poj 2349 Arctic Network

    http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  6. POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19113   Accepted: 6023 D ...

  7. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  8. POJ2349 Arctic Network(Prim)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16968   Accepted: 5412 D ...

  9. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

随机推荐

  1. android studio打包出现翻译问题

    错误信息: Error:(16) Error: "baidutieba_client_inavailable" is not translated in "en" ...

  2. Python学习之路--select解析

    sellect.poll.epoll三者的区别 select select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select()返回后, ...

  3. mono for android 各版本下载地址

    window下 在XamarinStudio 检查更新,会在这个目录下生成LOG和下载文件,所以可以从里面复制出来,查看真实下载地址 C:\Users\用户名\AppData\Local\Xamari ...

  4. spi接口的ds1302时钟芯片控制在lcd1602上显示

    spi接口的ds1302时钟芯片控制在lcd1602上显示                                                                        ...

  5. AWIT DBackup 0.0.20 发布,备份系统

    AWIT DBackup 0.0.20 修复了几个小 bug. AllWorldIT DBackup 是一个备份系统,为每个目录创建一个独立的压缩包,这更便于搜索. 特点: 使用 xz, bzip2, ...

  6. C#实现 word、pdf、ppt 转为图片

    office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...

  7. Sensor(PROXIMITY)

    package com.example.sensor01; import android.hardware.Sensor; import android.hardware.SensorEvent; i ...

  8. Sensor(ACCELEROMETER)

    package com.example.sensor01; import java.util.List; import android.hardware.Sensor; import android. ...

  9. 【面试必备】javascript的原型和继承

    原型.闭包.作用域等知识可以说是js中面试必考的东西,通过你理解的深度也就能衡量出你基本功是否扎实.今天来复习一下javascript的原型和继承,虽说是老生常谈的话题,但对于这些知识,自己亲手写一遍 ...

  10. fsfds

    ccc fs -fsd fsdfsfs