acm-Arctic Network(最小生成树)
来源:互联网 发布:数据录入员工作的细节 编辑:程序博客网 时间:2024/05/18 02:04
Arctic Network
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 10070 Accepted: 3334
Description
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.
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.
Input
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).
Output
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
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define MAXN 502using namespace std;struct Pos{int x,y;}pos[MAXN];struct Edg{int u,v;double w;}edg[MAXN*MAXN/2];int parent[MAXN];double d[MAXN];bool operator < (const Edg &x,const Edg &y){return x.w<y.w;}double getSqrt(int x1,int y1,int x2,int y2){returnsqrt((double)(y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));}int Find(int x){if(x!=parent[x])return parent[x]=Find(parent[x]);return x;}int main(){int N;scanf("%d",&N);while(N--){int S,P;scanf("%d%d",&S,&P);for(int i=0;i<P;i++){scanf("%d%d",&pos[i].x,&pos[i].y);}int m=0;for(int i=0;i<P;i++){for(int j=i+1;j<P;j++){edg[m].u=i;edg[m].v=j;edg[m++].w=getSqrt(pos[i].x,pos[i].y,pos[j].x,pos[j].y);}}sort(edg,edg+m);int count=0;for(int i=0;i<P;i++) parent[i]=i;for(int i=0;i<m;i++){int o=Find(edg[i].u);int p=Find(edg[i].v);if(o!=p){d[count++]=edg[i].w;parent[o]=p;}}printf("%.2lf\n",d[P-S-1]);}return 0;}
0 0
- acm-Arctic Network(最小生成树)
- POJ 2349 Arctic Network [最小生成树]
- uva 10369 - Arctic Network(最小生成树)
- poj 2349 (最小生成树)Arctic Network
- UVA 10369 - Arctic Network(最小生成树)
- ZOJ 1914 Arctic Network 最小生成树
- POJ-2349 Arctic Network 最小生成树
- poj2349 Arctic Network 最小生成树,kruskal
- Uva 10369 Arctic Network 最小生成树
- POJ 2349 Arctic Network 最小生成树
- poj-2349 Arctic Network 最小生成树
- poj 2349 Arctic Network 最小生成树
- POJ2349&ZOJ1914--Arctic Network【最小生成树】
- poj2349 Arctic Network(最小生成树)
- [poj2349 Arctic Network]最小生成树
- POJ2349 Arctic Network 最小生成树
- UVA 10369- Arctic Network(最小生成树)
- poj 2349 Arctic Network 最小生成树
- 面试4---集合对比
- 《C Primer Plus》 学习笔记系列之(四)
- 我跟SAP那点事(四)
- 手机app
- 两年未更新博客了
- acm-Arctic Network(最小生成树)
- hdu-2099-整除的尾数
- hdu 1908 Double Queue ( splay )
- 爆搜解hdu1572下沙小面的(2)
- 【NOIP 2009】Hankson的趣味题 分析&渣程序(增补对于大质数的分析)
- POJ - 1061 青蛙的约会 (扩展欧几里得算法)
- java
- 一个二进制算法
- 给大家讲个笑话吧