还是一道水题 只是边需要自己处理 由于点很少 n²的跑出来就好了 在把对应的各项都改成double型就可以了
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include<set>
#include<stack>
#define bug puts("bugbugbug");
using namespace std;
typedef long long ll;
const int maxm=10005;
int f[105];
int n,m;
struct node
{
int x, y;
double v;
bool operator<(const node &b)const
{
if(this->v!=b.v)
return (this->v<b.v);
if(this->x!=b.x)
return (this->x<b.x);
return (this->y<b.y);
}
} e[maxm];
int find(int x)
{
return f[x]= f[x]==x?x:find(f[x]);
}
double Kruscal()
{
sort(e, e + m);
int cnt = n;
double ans = 0;
for(int i = 0; i <= n; i++) f[i] = i;
for (int i = 0; i < m; i++)
{
int x = find(e[i].x);
int y = find(e[i].y);
if (x != y)
{
f[x] = y;
cnt--;
ans += e[i].v;
if (cnt == 1) break;
}
}
if(cnt!=1)return -1;
return ans;
}
double x[1005],y[1005];
double D(int i,int j)
{
return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
m=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
double d=D(i,j);
if(d>=10&&d<=1000)
{
e[m].x=i;
e[m].y=j;
e[m++].v=d;
}
}
}
double ans=Kruscal();
if(ans==-1)
puts("oh!");
else
printf("%.1lf\n",ans*100);
}
}