/*
The first line of each test case contains 1 <= S <= 100, the number of satellite channels!
注意:S表示一共有多少个卫星,那么就是有 最多有S-1个通道! 然后将最小生成树中的后边的 S-1通道去掉就行了!
思路:最小生成树中的第 k 个最小边!
*/
//克鲁斯克尔算法.....
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; double x[], y[]; struct node{
int u, v;
double d;
}; bool cmp(node a, node b){
return a.d < b.d;
} int f[]; node nd[];
double ret[]; int getFather(int x){
return x==f[x] ? x : f[x]=getFather(f[x]);
} bool Union(int a, int b){
int fa=getFather(a), fb=getFather(b);
if(fa!=fb){
f[fa]=fb;
return true;
}
return false;
} int main(){
int n, m;
int t;
scanf("%d", &t);
while(t--){
scanf("%d%d", &m, &n);
for(int i=; i<=n; ++i){
scanf("%lf%lf", &x[i], &y[i]);
f[i]=i;
}
int cnt=;
for(int i=; i<n; ++i)
for(int j=i+; j<=n; ++j){
nd[cnt].u=i;
nd[cnt].v=j;
nd[cnt++].d=sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
}
sort(nd, nd+cnt, cmp);
int cc=;
for(int i=; i<cnt; ++i)
if(Union(nd[i].u, nd[i].v))
ret[cc++]=nd[i].d;
for(int i=; i<cc; ++i)
cout<<ret[i]<<"fdsf"<<endl;
printf("%.2lf\n", ret[n-m-]);
}
return ;
}
 //prim算法.......
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const double INF = 0x3f3f3f3f*1.0;
double x[], y[]; int n, m;
double map[][];
int vis[]; double ret[]; void prim(){
memset(vis, , sizeof(vis));
vis[]=;
for(int i=; i<=n; ++i)
ret[i]=INF;
int root=, p;
for(int i=; i<n; ++i){
double minLen=INF;
for(int j=; j<=n; ++j){
if(!vis[j] && ret[j]>map[root][j])
ret[j]=map[root][j];
if(!vis[j] && minLen>ret[j]){
minLen=ret[j];
p=j;
}
}
root=p;
vis[root]=;
}
} int main(){ int t;
scanf("%d", &t);
while(t--){
scanf("%d%d", &m, &n);
for(int i=; i<=n; ++i)
scanf("%lf%lf", &x[i], &y[i]);
for(int i=; i<n; ++i)
for(int j=i+; j<=n; ++j)
map[i][j]=map[j][i]=sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j])); prim();
sort(ret, ret+n+); printf("%.2lf\n", ret[n-m+]);
}
return ;
}

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. 今天自己解决了两个问题(IE10 type slow ChromeDriver erro)

    都是通过google解决的,其实本应该很快解决,可是因自己粗心,大写小错了,加上java基础不过关, "webdriver.chrome.driver"中的webdriver应是全 ...

  2. 跟visual studio 集成的git插件

    目前有三个,git extension,微软的 visual studio tools for git extension,还有git source control provider 经测试,最好用的 ...

  3. MyEclipse 常用操作

    1.使用JREBEL插件包实现myeclipse修改类文件后无须重启 在Myeclipse中的window-preferences(搜索tomcat)->然后到tomcatx.x下的-jdk中配 ...

  4. Magicodes.WeiChat——版本发布历史

    购买地址:https://item.taobao.com/item.htm?id=520205558575 您可以在新标签页打开此图,以查看原始图片. Magicodes.WeiChat为湖南心莱信息 ...

  5. Android 自定义View 总结

    Android系统本身给我们提供十分丰硕的组件让我们实现包罗万象的UI效果,与此同时,我们也能够非常方便实现各种方法来实现各种强大的功能.通过继承现有的UI控件,我们也能够拓展现有的功能.我们也能够完 ...

  6. [.NET领域驱动设计实战系列]专题九:DDD案例:网上书店AOP和站点地图的实现

    一.引言 在前面一专题介绍到,要让缓存生效还需要实现对AOP(面向切面编程)的支持.所以本专题将介绍了网上书店案例中AOP的实现.关于AOP的概念,大家可以参考文章:http://www.cnblog ...

  7. kali linux Python开发环境初始化

    kali linux Python 黑客编程1 开发环境初始化 为什么要选择Python? Python作为目前Linux系统下最流行的编程语言之一,对于安全工作者的作用可以和C++相提并论.Pyth ...

  8. ZooKeeper学习第一期---Zookeeper简单介绍

    一.分布式协调技术 在给大家介绍ZooKeeper之前先来给大家介绍一种技术——分布式协调技术.那么什么是分布式协调技术?那么我来告诉大家,其实分布式协调技术主要用来解决分布式环境当中多个进程之间的同 ...

  9. 用1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列,如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连。

    最近在看算法,看到这个题,觉得挺经典的,收起. 分析: 1 .把问题归结为图结构的遍历问题.实际上6个数字就是六个结点,把六个结点连接成无向连通图,对于每一个结点求这个图形的遍历路径,所有结点的遍历路 ...

  10. 技术渣如狗,面试虐成猴——本科楼主UC笔试加处女一面全纪录

    背景——楼主为广州某校小本一枚,学习成绩渣(班里排名几乎倒数),技术基础渣(算是会敲代码,但很多计算机网络.操作系统的知识都只有模糊的印象).在舍友的鼓励下,收到广州UC的面试通知后,勇敢来到公司直面 ...