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.
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).
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.
1 2 4 0 100 0 300 0 600 150 750
212.13
思路:
嗯这个题目不难 嗯主要在于要理解题意其实我看不懂 是百度翻译和看别人博客才知道这个题是在说什么致命啊
嗯题目的意思就是说 有m个.....所以就要有m-1条之间的通路才能把它连接起来 其中分两个方式 一种无线一种是卫星通道 卫星通道可以随意 而无线电不行因为线越长花费就越高 所以是不可以的 所以尽量把长德都弄成卫星通道
然后还有就是 比如有两个卫星通道那么只有一条线是可以被省去的 其实相当于sort之后 输出第n个的最大数字 大体就是这个意思 没了
c++代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
double store[550];
int pre[550];
struct node
{
int u;
int v;
double w;
}sall[130000];
bool cmp(node a,node b)
{
return a.w<b.w;
}
bool cmp1(int a,int b)
{
return a>b;
}
int find(int x)
{
if(pre[x]==x)
return x;
else
{
pre[x]=find(pre[x]);
return pre[x];
}
}
int merge(int x,int y)
{
int t1=find(x);
int t2=find(y);
if(t1!=t2)
{
pre[t2]=t1;
return 1;
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
int n,m,i,j;
double x[550],y[550];
while(t--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++)
scanf("%lf%lf",&x[i],&y[i]);
int k=0;
for(i=1;i<=500;i++)
pre[i]=i;
for(i=1;i<=m;i++)
for(j=i+1;j<=m;j++)
{
k++;
sall[k].u=i;
sall[k].v=j;
sall[k].w=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
sort(sall+1,sall+k+1,cmp);
int count=0;
for(i=1;i<=k;i++)
{
if(merge(sall[i].u,sall[i].v))
{
count++;
store[count]=sall[i].w;
}
if(count==m-1)
break;
}
sort(store+1,store+count+1,cmp1);
printf("%.2f\n",store[n]);
}
return 0;
}