Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1875
# Include <iostream> // 2235167 2010-03-23 16:21:03 accepted 1875 312 Ms 352 k 1567 B C ++ regret
# Include <algorithm> // The efficiency is really low. The algorithm still needs to be provided. Where is the time consumed ??
# Include <cstdio>
# Include <cmath>
Int AA [4951];
Using namespace STD;
Struct stu1
{
Int x1;
Int Y1;
} DF1 [2, 103];
Struct stu2
{
Int X2;
Int Y2;
Double distance;
} Df2 [2, 4951];
Int CMP (stu2 A, stu2 B)
{
Return A. distance <B. distance;
}
Int find (int x)
{
Int r = X;
While (R! = AA [R])
R = AA [R];
Return R;
}
Void mergy (int A, int B)
{
If (A> B)
AA [B] =;
Else
AA [a] = B;
}
Int main ()
{
Int t, n, I, j, Count, WW;
Double sum, DIS;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N );
For (I = 0; I <n; I ++)
Scanf ("% d", & DF1 [I]. X1, & DF1 [I]. Y1 );
Count = 0;
For (I = 0; I <n-1; I ++)
For (j = I + 1; j <n; j ++)
{
Dis = SQRT (1.0*(DF1 [I]. x1-DF1 [J]. x1) * (DF1 [I]. x1-DF1 [J]. x1) + (DF1 [I]. y1-DF1 [J]. y1) * (DF1 [I]. y1-DF1 [J]. y1 )));
If (DIS <10 | dis> 1000)
Continue;
Else
{
Df2 [count]. X2 = I + 1;
Df2 [count]. y2 = J + 1;
Df2 [count]. Distance = DIS;
Count ++;
}
}
Sort (df2, df2 + count, CMP );
For (I = 1; I <= N * (n-1)/2; I ++)
AA [I] = I;
WW = 0;
Sum = 0; // forget the initial statement
For (I = 0; I <count; I ++)
{
Int A = find (df2 [I]. x2 );
Int B = find (df2 [I]. Y2 );
If (! = B)
{
Sum + = df2 [I]. distance;
Mergy (A, B );
WW ++;
}
}
If (WW = N-1)
Printf ("% 0.1lf/N", 100 * sum );
Else
Printf ("Oh! /N ");
}
}
/*
# Include <iostream> // 2235212 2010-03-23 16:25:50 time limit exceeded 1875 1000 ms 408 K 1648 B C ++ regret
# Include <algorithm>
# Include <cstdio>
# Include <cmath>
Int AA [9910];
Using namespace STD;
Struct stu1
{
Int x1;
Int Y1;
} DF1 [2, 103];
Struct stu2
{
Int X2;
Int Y2;
Double distance;
} Df2 [2, 9910];
Int CMP (stu2 A, stu2 B)
{
Return A. distance <B. distance;
}
Int find (int x)
{
Int r = X;
While (R! = AA [R])
R = AA [R];
Return R;
}
Void mergy (int A, int B)
{
If (A> B)
AA [B] =;
Else
AA [a] = B;
}
Int main ()
{
Int t, n, I, j, num, Count, flag;
Double sum, DIS;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N );
For (I = 0; I <n; I ++)
Scanf ("% d", & DF1 [I]. X1, & DF1 [I]. Y1 );
Count = 0;
Flag = 0;
For (I = 0; I <n-1; I ++)
{
Int TT = 0;
For (j = 0; j <n; j ++)
{
If (I! = J) // The processing is not good here, so I can make a lot of useless judgments.
{
Dis = SQRT (1.0*(DF1 [I]. x1-DF1 [J]. x1) * (DF1 [I]. x1-DF1 [J]. x1) + (DF1 [I]. y1-DF1 [J]. y1) * (DF1 [I]. y1-DF1 [J]. y1 )));
If (DIS <10 | dis> 1000)
T ++;
Else
{
Df2 [count]. X2 = I + 1;
Df2 [count]. y2 = J + 1;
Df2 [count]. Distance = DIS;
Count ++;
}
}
}
If (TT = N-1)
{
Flag = 1;
Break;
}
}
If (flag = 1)
Printf ("Oh! /N ");
Else
{
Sort (df2, df2 + count, CMP );
For (I = 1; I <= N * (n-1)/2; I ++)
AA [I] = I;
Sum = 0;
For (I = 0; I <count; I ++)
{
Int A = find (df2 [I]. x2 );
Int B = find (df2 [I]. Y2 );
If (! = B)
{
Sum + = df2 [I]. distance;
Mergy (A, B );
}
}
Printf ("% 0.1lf/N", 100 * sum );
}
}
}