Description
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
Output
Sample Input
1 2 4 0 100 0 300 0 600 150 750
Sample Output
212.13#include<stdio.h> #include<algorithm> #include<math.h> using namespace std; int n,k,x[1001],y[1001],idx,f[1001],s[1001],how,S; struct node { int a,b,len; }w[200001]; bool com(const node &g,const node &h) { return g.len<h.len; } int find(int p) { if(f[p]!=p) f[p]=find(f[p]); return f[p]; } void merge(int z,int v) { int fx=find(z); int fy=find(v); how--; if(s[fx]>s[fy]) f[fy]=fx,s[fx]+=s[fy]; else f[fx]=fy,s[fy]+=s[fx]; } int main() { scanf("%d",&n); while(n--) { scanf("%d%d",&S,&k); how=k; idx=0; for(int i=1;i<=k;i++) { scanf("%d%d",&x[i],&y[i]); f[i]=i,s[i]=1; } for(int i=1;i<=k;i++) { for(int j=1;j<i;j++) { w[++idx].len=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]); w[idx].a=i; w[idx].b=j; } } sort(w+1,w+idx+1,com); for(int i=1;i<=idx;i++) { if(find(w[i].a)==find(w[i].b)) continue; merge(w[i].a,w[i].b); if(how==S) { printf("%.2lf\n",sqrt(double(w[i].len))); break; } } } }
AC 顶一个
6679


&spm=1001.2101.3001.11974&articleId=77146001&d=1&t=3&u=cb9594c75b1b4ccfbc415727532afde5)

被折叠的 条评论
为什么被折叠?



