【最小生成树】POJ 2349 Arctic Network
来源:互联网 发布:淘宝八大山人书法全集 编辑:程序博客网 时间:2024/06/10 17:09
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.
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
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
裸题:
#include<iostream>#include<cmath>#include<algorithm>#include<cstdio>using namespace std;const int MAXN=500;struct node{ int beg; int end; double s;};node a[MAXN*MAXN];struct point{ int x; int y;};point b[MAXN];int fa[MAXN];void read(int &x){ x=0; char c=getchar(); while(c<'0'||c>'9')c=getchar(); while(c>='0'&&c<='9') { x=x*10+c-'0'; c=getchar(); }}int found(int x){ if(fa[x]!=x)fa[x]=found(fa[x]); return fa[x];}int comp(const node&i,const node&j){ return i.s<j.s;}int main(){ int s,q; read(s); for(q=1;q<=s;q++) { int s,p; double ans; read(s);read(p); for(int i=1;i<=p;i++) { fa[i]=i; read(b[i].x); read(b[i].y); } int k=0; for(int i=1;i<=p;i++) { for(int j=i+1;j<=p;j++) { k++; a[k].beg=i; a[k].end=j; a[k].s=(double)sqrt((double)(b[i].x-b[j].x)*(b[i].x-b[j].x)+(double)(b[i].y-b[j].y)*(b[i].y-b[j].y)); } } sort(a+1,a+k+1,comp); int t=0; for(int i=1;i<=k;i++) { if(found(a[i].beg)!=found(a[i].end)) { fa[found(a[i].beg)]=found(a[i].end); t++; if(t+s==p) { ans=a[i].s; break; } } } printf("%.2lf\n",ans); } return 0;}
- POJ 2349 Arctic Network [最小生成树]
- poj 2349 (最小生成树)Arctic Network
- POJ-2349 Arctic Network 最小生成树
- POJ 2349 Arctic Network 最小生成树
- poj-2349 Arctic Network 最小生成树
- poj 2349 Arctic Network 最小生成树
- poj 2349 Arctic Network 最小生成树
- poj 2349 Arctic Network 最小生成树~~
- Arctic Network (poj 2349 最小生成树)
- POJ 2349Arctic Network【最小生成树】
- 【最小生成树】POJ 2349 Arctic Network
- POJ 2349 Arctic Network 最小生成树
- POJ-2349-Arctic Network [最小生成树]
- POJ 2349 Arctic Network (最小生成树)
- POJ 2349 Arctic Network (最小生成树)
- POJ Arctic Network 【最小生成树】
- Arctic Network--POJ(最小生成树)
- poj 2349 Arctic Network(最小瓶颈生成树)
- yii定义常量
- 学习记录
- (4.5.5.5)Espresso的进阶: ViewAssertions
- 开张
- ThinkPHP分页总结
- 【最小生成树】POJ 2349 Arctic Network
- 如何绕过PowerShell Execution Policy限制?
- (4.5.5.6)Espresso的进阶: IdlingResource
- bzoj2152: 聪聪可可
- python运行异常
- 基于 React Native 的开源项目
- HBase数据导入之completebulkload方式
- 第三十九讲项目七
- 微服务开发的12项要素