Arctic Network
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 10718 | Accepted: 3515 |
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.
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/* 题目大意:有s个站点,p个点,找要把所有点都连起来,但是这些点的连线都相同,要求连线最短 思路:先找出最小生成树,把每段距离记录下来,因为有s个站点,所以有s个站点不需要连接,将距离从大到小排序,有s-1段是不需要的,只要找出来第s段就可以 Time:2014-10-16 22:12 */ #include<cstdio> #include<cstring> #include<algorithm> #include<climits> #include<cmath> using namespace std; #define MAX 510 #define INF 10000*10010 struct Point{ double x,y; }p[MAX]; int N,M; double map[MAX][MAX],d[MAX]; double minEdge[MAX]; int k; bool cmp(double a,double b){return a>b;} double dis(Point a,Point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } void Prim(){ double Mst; bool vis[MAX]; memset(d,0,sizeof(d)); memset(vis,0,sizeof(vis)); for(int i=1;i<=M;i++){ d[i]=map[1][i]; //printf("%.2lf ",d[i]); } d[1]=0;vis[1]=true; for(int i=1;i<=M;i++){ double minV=INF*1.0;int u=1; for(int j=1;j<=M;j++){ if(!vis[j]&&minV>d[j]){ minV=d[j]; u=j; } } //printf("%lf\n",d[u]); if(minV==INF) return ;//Mst; //Mst+=d[u]; minEdge[k++]=minV; vis[u]=true; for(int j=1;j<=M;j++){ if(!vis[j]&&d[j]>map[u][j]){ d[j]=map[u][j]; } } } //return Mst; } void GetMap(){ for(int i=1;i<=M;i++) for(int j=1;j<=M;j++) if(i!=j) map[i][j]=map[j][i]=dis(p[i],p[j]); else map[i][j]=0; } int main(){ int T,S; scanf("%d",&T); while(T--){ k=0; scanf("%d%d",&S,&M); N=(M*(M-1)>>1); for(int i=1;i<=M;i++){ scanf("%lf%lf",&p[i].x,&p[i].y); } GetMap(); /* for(int i=1;i<=M;i++){ for(int j=1;j<=M;j++) printf("%.2lf ",map[i][j]); printf("\n"); }*/ Prim(); sort(minEdge,minEdge+k,cmp); //0---k S-1表示第S个 有S个站点,说明有S个不用连通 printf("%.2lf\n",minEdge[S-1]); } return 0; }