【最小生成树】POJ 2349 Arctic Network
2017-04-24 09:09
267 查看
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
12 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(最小生成树的第k大边证明)
- POJ 2349 Arctic Network (最小生成树第K大(小)边)
- POJ 2349 Arctic Network 最小生成树题解
- POJ 2349 Arctic Network(最小生成树之Prim)
- poj 2349 Arctic Network(图论:最小生成树)
- Arctic Network (poj 2349 最小生成树)
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
- POJ 2349 Arctic Network(最小生成树思想)
- POJ 2349 Arctic Network(最小生成树)
- Prim最小生成树【poj 2349 Arctic Network;poj 1287 NetWorking】
- POJ 2349 Arctic Network(最小生成树 kruscal or prim)
- poj 2349 (最小生成树)Arctic Network
- POJ - 2349 Arctic Network (最小生成树分块)
- POJ 2349 Arctic Network [最小生成树]
- 2349 poj &&uva 10369 Arctic Network【最小生成树】
- poj 2349 Arctic Network(最小瓶颈生成树)
- poj 2349 Arctic Network 最小生成树,求第k大条边
- poj-2349 Arctic Network 最小生成树
- POJ 2349 Arctic Network 最小生成树
- 【POJ】2349 - Arctic Network(最小生成树的第n条大边)(好题)