UVa - 10369 - Arctic Network ( 最小生成树 Kruscal )
来源:互联网 发布:linux path是什么 编辑:程序博客网 时间:2024/06/05 10:11
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel.
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
The first line of input contains N, the number of test cases. The first line of each test case contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000). For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.
Sample Input
12 40 1000 3000 600150 750
Sample Output
212.13
题目大意:国防部要让 p 个地方实现通信。实现通信的方式有2种,第一种是在该地方连接卫星(可以实现任意距离的通信),第二种是在两地之间建立无线电通信,建造成本和距离D成正比。现在有 s 个卫星,如果要实现 p 个地方的通信(直接或间接)。让D尽可能的小,求出最大的D。题目输入给出每个地方的坐标。
题目思路:构图后求出MST,那么较大的边尽可能都用卫星通信,剩下的最大的边就是要求的D。
#include<cstdio>#include<algorithm>#include<cmath>#define N 505using namespace std;double x[N],y[N];int f[N];int num,cnt,s,p;struct E{int a,b;double v;}e[N*N];bool cmp(E e1,E e2){return e1.v<e2.v;}int find(int x){return f[x] == x ? x : f[x] = find(f[x]);}void Kruscal(){sort(e,e+num,cmp);for(int i=0 ;i<num ;i++){int fa = find(e[i].a);int fb = find(e[i].b);if(fa!=fb){f[fa] = fb;cnt++;}if(cnt == p-s){printf("%.2f\n",e[i].v);break;}}}void init(){scanf("%d%d",&s,&p);for(int i=0 ;i<N ;i++){f[i] = i;}for(int i=0 ;i<p ;i++){scanf("%lf",&x[i]);scanf("%lf",&y[i]);}for(int i=0 ;i<p ;i++){for(int j=i+1 ;j<p ;j++){e[num].a = i;e[num].b = j;e[num++].v = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));}}}int t;int main(){scanf("%d",&t);while(t--){num = 0;cnt = 0;init();Kruscal();}return 0;}
- UVa - 10369 - Arctic Network ( 最小生成树 Kruscal )
- poj 2349 Arctic Network uva 10369(prim or kruscal最小生成树)
- uva 10369 - Arctic Network(最小生成树)
- UVA 10369 - Arctic Network(最小生成树)
- Uva 10369 Arctic Network 最小生成树
- UVA 10369- Arctic Network(最小生成树)
- UVA 10369Arctic Network【最小生成树】
- POJ 2349 Arctic Network 最小生成树 prim && kruscal
- uva 10369 - Arctic Network(最小生成树)
- (intermediate) 最小生成树 UVA 10369 - Arctic Network
- UVA - 10369 Arctic Network (最小生成树)
- 2349 poj &&uva 10369 Arctic Network【最小生成树】
- UVA 10369 - Arctic NetWork (求最小生成树)
- POJ 2349 Arctic Network(最小生成树 kruscal or prim)
- UVa 10369 - Arctic Network(求最小生成树的第k小边)
- UVa 10369 Arctic Network (Kruskal+最小生成树的第K小边)
- POJ 2349 Arctic Network [最小生成树]
- poj 2349 (最小生成树)Arctic Network
- MySQL Group Replication 介绍
- Git命令详解(下)
- Centos7安装完提示Initial setup of CentOS Linux 7 (core)
- UEditor在项目中的应用
- Maven学习 (二) Eclipse 上安装 Maven3插件
- UVa - 10369 - Arctic Network ( 最小生成树 Kruscal )
- excel怎么查某列重复的记录
- net core 中间件详解及项目实战
- React Native 之 Text的使用
- perl next和last
- Python Web框架Tornado运行和部署
- Xcode制作framework库
- 网络调侃用语编辑
- QDebug打印QString调试信息打印