标签:pac == ios amp math sqrt algo int mes
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=505;
int s,p,tot,cnt;
struct node{
int u,v;
}a[N];
struct Node{
int u,v;
double w;
}edge[N*N];
int f[N];
bool cmp(Node a,Node b){
return a.w<b.w;
}
int find(int x){
if(f[x]==x) return x;
return f[x]=find(f[x]);
}
int main(){
scanf("%d%d",&s,&p);
for(int i=1;i<=p;i++){
int x,y;
scanf("%d%d",&x,&y);
a[i].u=x; a[i].v=y;
}
for(int i=1;i<=p;i++)
for(int j=1;j<=p;j++){
if(i==j) continue;
edge[++cnt].w=sqrt((a[i].u-a[j].u)*(a[i].u-a[j].u)+(a[i].v-a[j].v)*(a[i].v-a[j].v));
edge[cnt].u=i;
edge[cnt].v=j;
}
for(int i=1;i<=p;i++) f[i]=i;
sort(edge+1,edge+cnt+1,cmp);
for(int i=1;i<=cnt;i++){
int r1=find(edge[i].u),r2=find(edge[i].v);
if(r1==r2) continue;
f[r1]=r2;
tot++;
if(tot==p-s){
printf("%.2f",edge[i].w);
}
}
return 0;
}
标签:pac == ios amp math sqrt algo int mes
原文地址:https://www.cnblogs.com/New-ljx/p/14784371.html