标签:
F.A.Qs | Home | Discuss | ProblemSet | Status | Ranklist | Contest | ModifyUser hyxzc | Logout | 捐赠本站 |
---|
1 #include<cstdio> 2 #include<cmath> 3 #include<iostream> 4 #include<algorithm> 5 #define maxn 1010 6 7 using namespace std; 8 9 int fa[maxn],n,m,cnt=0; 10 11 struct ss 12 { 13 int x; 14 int y; 15 }e[maxn]; 16 17 struct node 18 { 19 int u; 20 int v; 21 int w; 22 }s[maxn*maxn]; 23 24 int find(int x) 25 { 26 if (fa[x]==x) return x; 27 fa[x]=find(fa[x]); 28 return fa[x]; 29 } 30 31 bool cmp(node a,node b) 32 { 33 return a.w<b.w; 34 } 35 36 int main() 37 { 38 scanf("%d%d",&n,&m); 39 for (int i=1;i<=n;i++) 40 scanf("%d%d",&e[i].x,&e[i].y); 41 for (int i=1;i<=n;i++) 42 for (int j=i+1;j<=n;j++) 43 { 44 cnt=cnt+1; 45 s[cnt].u=i; 46 s[cnt].v=j; 47 s[cnt].w=(e[j].x-e[i].x)*(e[j].x-e[i].x)+(e[j].y-e[i].y)*(e[j].y-e[i].y); 48 } 49 sort(s+1,s+cnt+1,cmp); 50 int k=n; 51 for (int i=1;i<=n;i++) fa[i]=i; 52 for (int i=1;i<=cnt;i++) 53 { 54 int fa1=find(s[i].u),fa2=find(s[i].v); 55 if (fa1!=fa2) k--; 56 fa[fa1]=fa2; 57 if (k<m) {printf("%0.2lf\n",sqrt(s[i].w));return 0;} 58 } 59 }
标签:
原文地址:http://www.cnblogs.com/grhyxzc/p/5204466.html