UvaOJ10369 - Arctic Network
/*
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的更多相关文章
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- 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 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- poj 2349 Arctic Network
http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19113 Accepted: 6023 D ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
- POJ2349 Arctic Network(Prim)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16968 Accepted: 5412 D ...
- POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru
Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...
随机推荐
- strncpy和memcpy的区别
今天不小心在该用memcpy的时候,用了strncpy使自己吃了亏,所以写出这个博文. memcpy就是纯字节拷贝,而strncpy就不同了,字符串是以'\0'结尾的.如果一个字符buffer长度为6 ...
- C++的一个奇技淫巧
C++如何写一个函数,得到一个数组的长度呢? size_t GetArrayLength(int Array []) { return sizeof(Array)/sizeof(Array[0]); ...
- Android中的IntentService
首先说下,其他概念:Android中的本地服务与远程服务是什么? 本地服务:LocalService 应用程序内部------startService远程服务:RemoteService androi ...
- 企业搜索引擎开发之连接器connector(二十九)
在哪里调用监控器管理对象snapshotRepositoryMonitorManager的start方法及stop方法,然后又在哪里调用CheckpointAndChangeQueue对象的resum ...
- 地图、定位 CLLocationManager CLGeocoder CLPlacemark
地图.定位 一.基本知识点 定位: 1.info.plist文件设置 ios8以后,使用定位需要在info.plist文件中添加两个字段NSLocationAlwaysUsageDescription ...
- Linux内核--网络栈实现分析(七)--数据包的传递过程(下)
本文分析基于Linux Kernel 1.2.13 原创作品,转载请标明http://blog.csdn.net/yming0221/article/details/7545855 更多请查看专栏,地 ...
- 使用的组件:Layui
Layui 经典模块化前端框架 由职业前端倾情打造,面向所有层次的前后端程序猿,中国最容易使用的前端UI解决方案 Layui 出蛋于2016年金秋,是一款带着浓烈情怀的国产前端UI框架,她追求极简,又 ...
- week 2 日志
周二 css知多少(3)——样式来源与层叠规则 http://www.cnblogs.com/wangfupeng1988/p/4277959.htmlcss知多少(4)——解读浏览器默认样式 htt ...
- Oracle基本数据字典:v$database、v$instance、v$version、dba_objects
v$database: 视图结构: SQL> desc v$database; Name Null? Type - ...
- .Net Core CLI在CentOS7的安装及使用简介
1. 安装libunwind cd /usr/local/src wget http://download.savannah.gnu.org/releases/libunwind/libunwind- ...