写个最小生成树换换口味...比较水的一道题..任意姿势就过了..
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int f[102];
int find(int x)
{
if(x!=f[x])
return f[x]=find(f[x]);
return x;
}
struct node
{
int x,y;
double s;
} map[20002];
struct p
{
int x,y;
} dian[102];
int cmp(node a,node b)
{
return a.s<b.s;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
for(int i=0;i<=n;i++)
f[i]=i;
for(int i=0; i<n; i++)
cin>>dian[i].x>>dian[i].y;
int k=0;
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
map[k].x=i,map[k].y=j;
map[k].s=sqrt((dian[i].x-dian[j].x)*(dian[i].x-dian[j].x)+(dian[i].y-dian[j].y)*(dian[i].y-dian[j].y));
if(map[k].s<=1000&&map[k].s>=10)
k++;
}
}
sort(map,map+k,cmp);
int t=0;
double ans=0;
for(int i=0; i<k; i++)
{
int x=find(map[i].x);
int y=find(map[i].y);
if(x!=y)
{
f[x]=y;
ans+=map[i].s;
t++;
}
if(t==n-1)
break;
}
if(t==n-1)
printf("%.1f\n",ans*100);
else
printf("oh!\n");
}
return 0;
}