POJ - 2349 Arctic Network

來源:互聯網
上載者:User

標籤: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

12 40 1000 3000 600150 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 node12 {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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.