POJ2349 Arctic Network

 

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 17990 Accepted: 5723

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

Source

 
已有S个卫星电话可以部署,部署了卫星电话的城市之间通话代价为0
一眼可以看出这是一个最小生成树问题,那么当然要利用S,贪心地把生成树中的S-1条边消掉。剩下的最长边就是答案
 
 1 /*by SilverN*/
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<vector>
 8 using namespace std;
 9 const int mxn=610;
10 int read(){
11     int x=0,f=1;char ch=getchar();
12     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
13     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
14     return x*f;
15 }
16 struct point{
17     int x,y;
18 }p[mxn];
19 double dist(int a,int b){
20     return sqrt((double)(p[a].x-p[b].x)*(p[a].x-p[b].x)+(double)(p[a].y-p[b].y)*(p[a].y-p[b].y));
21 }
22 struct edge{
23     int x,y;
24     double d;
25 }e[mxn*mxn];
26 int cmp(const edge a,const edge b){
27     return a.d<b.d;
28 }
29 int s,n,cnt;
30 //
31 int fa[mxn];
32 int find(int x){
33     if(fa[x]==x)return x;
34     return fa[x]=find(fa[x]);
35 }
36 void kruskal(int s){
37     for(int i=1;i<=n;++i)fa[i]=i;
38     int num=1;
39     double ans=0;
40     for(int i=1;i<=cnt;++i){
41         int f1=find(e[i].x);
42         int f2=find(e[i].y);
43         if(f1!=f2){
44             fa[f1]=f2;
45             ans=max(ans,e[i].d);
46             num++;
47         }
48         if(num==n-s)break;
49     }
50     printf("%.2f\n",ans);
51     return;
52 }
53 int T;
54 int main(){
55     T=read();
56     int i,j;
57     while(T--){
58         s=read();n=read();--s;
59         for(i=1;i<=n;++i){
60             p[i].x=read();p[i].y=read();
61         }
62         cnt=0;
63         for(i=1;i<n;++i)
64          for(j=i+1;j<=n;++j){
65              e[++cnt].x=i;e[cnt].y=j;
66              e[cnt].d=dist(i,j);
67          }
68         sort(e+1,e+cnt+1,cmp);
69         kruskal(s);
70     }
71     return 0;
72 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/6017394.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值