Arctic Network POJ - 2349
标签:bsp fir cstring sqrt work efi str namespace turn
#include
#include
#include
#include
#include#define x first
#define y second
using namespace std;
typedef pairint,int>PII;
const int N=510,M=N*N/2;
int n,k,m;
struct edge
{
int a,b;
double w;
} e[M];
double get_dist(PII a,PII b)
{
int dx=a.x-b.x;
int dy=a.y-b.y;
return sqrt(dx*dx+dy*dy);
}
bool cmp(edge a,edge b)
{
return a.wb.w;
}
PII q[M];
int p[N];
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
int main()
{
int t;
cin>>t;
while(t--)
{
m=0;
cin>>k>>n;
for(int i=0; i)
cin>>q[i].x>>q[i].y;
for(int i=0; i)
for(int j=0; j)
e[m++]= {i,j,get_dist(q[i],q[j])};
sort(e,e+m,cmp);
for(int i=0; i)
p[i]=i;
int cnt=n;
double res=0;
for(int i=0; i)
{
if(cntk)
break;
int a=find(e[i].a);
int b=find(e[i].b);
double w=e[i].w;
if(a!=b)
{
p[a]=b;
cnt--;
res=w;
}
}
//不能用lf
printf("%.2f\n",res);
}
return 0;
}
Arctic Network POJ - 2349
标签:bsp fir cstring sqrt work efi str namespace turn
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12240203.html
评论