- Time: 2016-04-13-23:58:24
- Title Number: [2016-04-13][hdu][1875][smooth works re-continued]
- The smallest spanning tree in the specified range is the right edge
- Analysis: Kruskal The merger of the time to judge, and finally determine whether the combined edge number is n-1
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 100 + 10;
struct Point{
int x,y;
Point(int a=0,int b=0):x(a),y(b){}
}p[maxn];
struct Edge{
int v C ;
edge ( int a = 0 int b = 0 int cc = 0 ): u ( a v ( b c ( cc ) {}
bool operator < (const Edge & a)const{
return c < a.c;
}
}e[maxn * maxn];
int fa[maxn];
int fnd(int x){
return x == fa[x]?x:fa[x] = fnd(fa[x]);
}
void ini(int n){
for(int i = 0 ; i <= n ; ++i){
fa[i] = i;
}
}
int dis(int a,int b){
return (P[a].x-P[b].x)*(P[a].x-P[b].x) + (P[a].y-P[b].y) * (P[a].y-P[b].y);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
ini(n);
for(int i = 0 ; i < n ; ++i){
scanf("%d%d",&p[i].x,&p[i].y);
}
int cnt = 0;
for ( int i = 0 I < n ++ i ) {
for ( int J = 0 ; J < n ++ j ) {
e[cnt++] = Edge(i,j,dis(i,j));
}
}
sort(e,e+cnt);
int k = 0;double ans = 0;
for(int i = 0 ; i < cnt ; ++i){
int f1 = fnd(e[i].u);
int F2 = fnd ( E [ i . v
if ( f1 != F2 && e [ i c >= 100 && e [ i . c <= 1000 * 1000 Span class= "pun") {
fa[f1] = f2;
ans += sqrt(double( e[i].c));
++k;
}
if(k == n - 1) break;
}
if(k == n - 1)
printf("%.1lf\n",ans * 100);
else puts("oh!");
}
return 0;
}
From for notes (Wiz)
[2016-04-13] [HDU] [1875] [Smooth works re-continued]