/*
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. 学习django之构建Web是Meta嵌套类的几处使用

    Django中meta嵌套类的使用 1.模型中使用嵌套类 在定义抽象模型时如: class Meta : abstract=true 用来指明你创建的模型是一个抽象基础类的模型继承. 2.在一个对象对 ...

  2. 转 powerdesigner12.5在64位JDK下连接mysql数据库问题

    前因:由于项目在研发的过程中,数据库字段需要不停的增加和修改,导致最初设计的数据库原型无法使用,后来就想到用powerdesinger来反转数据库表结构. 环境:win7 64位系统,本机装有64位j ...

  3. android 开发禁止系统修改app的字体大小

    重写activity的getResources方法,一般在BaseActivity中重写就好了,其他activity继承BaseActivity //设置字体大小不随手机设置而改变 @Override ...

  4. [1008]harder_prime

    素数定义:一个大于1的整数,如果它的约数如果只有1和它本身,那么它就是一个素数. 回文数定义:一个整数把它的各位数字倒过来还是它本身,那么它就是回文数,比如说2,99,393. 回文素数定义:一个数如 ...

  5. chrome插件开发-消息机制中的bug与解决方案

    序言 最近开发chrome插件,涉及到消息传递机时按照教程去敲代码,结果总是不对.研究了大半天终于找到原因,现在记录下. 程序 插件程序参考官网 chrome官网之消息传递机制, 不能FQ的同事也可以 ...

  6. Manifesto of the Communist Party

    A spectre is haunting Europe – the spectre of communism. All the powers of old Europe have entered i ...

  7. python Scrapy

    由于项目要使用新闻,大量的数据所以想到了python的scrapy 下面大致讲一讲如何安装使用,直到整个新闻采集模块完成,网址什么的自己找 这里只是示范这里的项目环境是python 2.66 cent ...

  8. 图解,为多个oracle数据库下添加ArcSde实例

    最开始肯定要先建一个oracle数据库,我假设名称为dbgis 1, 2, 3, 不重新指定就会出现这个错误,因为以前有sde.dbf文件了 4, 5, 6, 7, 8, 如果以前授权成功过就会出现这 ...

  9. MySQL7:视图

    什么是视图 数据库中的视图是一个虚拟表.视图是从一个或者多个表中导出的表,视图的行为与表非常相似,在视图中用户可以使用SELECT语句查询数据,以及使用INSERT.UPDATE和DELETE修改记录 ...

  10. Linux4:useradd、userdel、passwd、groupadd、chgrp、chown、df、du、sort、wget

    useradd 添加新的用户账号,只有root账户可以操作 -d 目录:指定用户主目录(默认在home下),若此目录不存在可同时使用-m创建主目录 -g 用户组:指定用户所属的用户组 -G 用户组:指 ...