poj 2349 Arctic Network

来源:互联网 发布:电脑刺绣软件 编辑:程序博客网 时间:2024/06/03 12:29

Arctic Network

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 15   Accepted Submission(s) : 4
Problem 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 40 1000 3000 600150 750
 

Sample Output
212.13
题中说有在北极有几个地方需要保持信息连接,卫星可以任意远的两个地方连接,而无线电则有距离限制,求需要的无线电的辐射长度最小是多少!
分析下题:首先建最小树,距离远的用卫星连接,而剩下的距离中的最大值则为满足条件的无线电辐射长度!
上代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int per[260000],n,m;double a[260000];struct node{    int x,y;    double w;}s[260000];bool cmp(node x,node y)//排序 {    return x.w<y.w;}void init(){    for(int i=0;i<=n;i++)    per[i]=i;}int find(int x)//查找 {    int i,j,t=x;    while(t!=per[t])    t=per[t];    i=x;    while(i!=t)    {        j=per[i];        per[i]=t;        i=j;    }    return t;}bool join(int x,int y)//合并 {    int fx=find(x);    int fy=find(y);    if(fx!=fy)    {        per[fx]=fy;        return true ;    }    return false;}int main(){    int i,j,n1;    scanf("%d",&n1);    while(n1--)    {        double x[600],y[600];        scanf("%d%d",&m,&n);        init();        for(i=0;i<n;i++)            scanf("%lf%lf",&x[i],&y[i]);            int k=0;            for(i=0;i<n;i++)            {                for(j=i+1;j<n;j++)                {                    s[k].x=i;                    s[k].y=j;                    s[k++].w=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));                }            }            sort(s,s+k,cmp);            int t=0;            for(int i=0 ; i<k ;  i++)            {                if(join(s[i].x,s[i].y))                a[t++]=s[i].w;            }            printf("%.2f\n",a[t-m]);    }    return 0;}


0 0