码迷,mamicode.com
首页 > Web开发 > 详细

POJ - 2349 Arctic Network

时间:2017-08-10 19:31:26      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:cee   eterm   follow   cout   location   reg   input   bsp   dep   

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
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 
 7 using namespace std;
 8 
 9 int f[505];
10 double dian[505][2];
11 struct node
12 {
13     int u,v;
14     double w;
15     friend bool operator <(node x,node y)
16     {
17         return x.w<y.w;
18     } 
19 }G[250005];
20 
21 int find(int x)
22 {
23     if(x!=f[x])
24         return find(f[x]);
25     return x;
26 }
27 
28 int main()
29 {
30     int n,m,T,S;
31     cin>>T;
32     while(T--)
33     {
34         scanf("%d%d",&S,&n);
35         memset(G,0,sizeof(G));
36         m=0;
37         for(int i=0;i<=n;i++)
38             f[i]=i;
39         for(int i=0;i<n;i++)
40             cin>>dian[i][0]>>dian[i][1];
41         for(int i=0;i<n;i++)
42             for(int j=i+1;j<n;j++)
43             {
44                 double w1=sqrt((dian[i][0]-dian[j][0])*(dian[i][0]-dian[j][0])+(dian[i][1]-dian[j][1])*(dian[i][1]-dian[j][1]));
45                 G[m].u=i;
46                 G[m].v=j;
47                 G[m++].w=w1;
48             }
49         sort(G,G+m);
50         double ans=0;
51         int s=S-1;
52         for(int i=0;i<m;i++)
53         {
54             int f1=find(G[i].u);
55             int f2=find(G[i].v);
56             if(f1!=f2)
57             {
58                 f[f2]=f1;
59                 ans=G[i].w;
60                 s++;
61             //    cout<<G[i].u<<" "<<G[i].v<<endl;
62             }
63             if(s==n-1)
64                 break;
65         }
66         //cout<<"s "<<s<<endl;
67         printf("%.2f\n",ans);
68     }
69     
70     return 0;
71 }

 

POJ - 2349 Arctic Network

标签:cee   eterm   follow   cout   location   reg   input   bsp   dep   

原文地址:http://www.cnblogs.com/xibeiw/p/7340565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!