/*
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. 【转】COM技术内幕(笔记)

    COM技术内幕(笔记) COM--到底是什么?--COM标准的要点介绍,它被设计用来解决什么问题?基本元素的定义--COM术语以及这些术语的含义.使用和处理COM对象--如何创建.使用和销毁COM对象 ...

  2. int 和 string 相互转换(简洁版)

    string int2str(int x) { return x ? num2str(x/10)+string(1,x%10+'0') : "";} int str2int(str ...

  3. erlang学习笔记(shell命令)

    erlang shell 命令: help(). 可以查看erlang shell内置命令. 比如:m(Mod),可以查看模块Mod. 待续..

  4. XAF 官方问题笔记

    1.How to print report direct, and print preview via an simple action? 如何通过一个按钮直接打印报表或者打印预览报表 https:/ ...

  5. docker pull certification error

    export DOMAIN_NAME=<my-dtr-domain> echo -n | openssl s_client -showcerts -connect itapregistry ...

  6. chrome浏览器root用户运行

    vim /usr/bin/google-chrome 58 exec -a "$0" "$HERE/chrome" "$PROFILE_DIRECTO ...

  7. Linux(centeros)下安装jdk

    首先需要说明的是有的Linux系统自带jdk,这个jdk是openjdk,可以通过java-version查看 所以安装的步骤是,首先删除系统自带的(如果有)openjdk 1. rpm -qa | ...

  8. centos 清理内存缓存

    读写文件时,Linux内核为了提高读写效率与速度,会将文件在内存中进行缓存,这就是Cache Memory(缓存内存).即使程序运行结束后,Cache Memory也不会自动释放.这就会导致程序频繁读 ...

  9. 在CentOS上搭建svn服务器及注意事项

    系统环境 CentOS 5.9 推荐使用yum install安装,比较简单   一.检查是否已经安装其他版本svn # rpm -qa subversion #卸载svn # yum remove ...

  10. blender 2.6 快捷键

    右键单击 选中 A 取消选择/全选 中键拖动 旋转 中键滚动放大/缩小 Shift+中键拖动 平移 右上斜线三角区域拖动 产生新视窗 Shift+c准星复位 Num1前视图 Ctrl+Num1后视图 ...