#include<bits/stdc++.h>
using namespace std;
double x[100+5],y[100+5];
double e[100+5][100+5];
const double inf=99999999;
int main()
{
int n,i,j,k;
double low[100+5],ans;
while(~scanf("%d",&n))
{
for(i=0;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(i==j) e[i][j]=inf;
else
{
e[i][j]=e[j][i]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
}
for(i=0;i<n;i++)
low[i]=e[0][i];
low[0]=-1;
ans=0;
for(i=1;i<n;i++)
{
double t=inf;
for(k=0;k<n;k++)
{
if(low[k]!=-1&&low[k]<t)
{
j=k;
t=low[k];
}
}
ans+=t;
low[j]=-1;
for(k=0;k<n;k++)
{
low[k]=min(low[k],e[j][k]);
}
}
printf("%.2f\n",ans);
}
return 0;
}
hdu 4463 Outlets
最新推荐文章于 2019-03-03 16:23:22 发布