-
Notifications
You must be signed in to change notification settings - Fork 0
/
10034.cpp
50 lines (42 loc) · 1.17 KB
/
10034.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
struct Node {
double x, y;
};
int main(void)
{
int i, j, k, times, len, done, minIndex;
Node list[101], tmpN;
double sum, min, tmpD;
scanf("%d", ×);
while (times-- > 0) {
scanf("%d", &len);
for (i = 0; i < len; ++i)
scanf("%lf %lf", &list[i].x, &list[i].y);
sum = 0;
done = 1;
for (i = 1; i < len; ++i) {
min = DBL_MAX;
for (j = 0; j < done; ++j)
for (k = done; k < len; ++k) {
tmpD = pow(list[j].x - list[k].x, 2) + pow(list[j].y - list[k].y, 2);
if (tmpD < min) {
min = tmpD;
minIndex = k;
}
}
sum += sqrt(min);
memcpy(&tmpN, list + done, sizeof(Node));
memcpy(list + done, list + minIndex, sizeof(Node));
memcpy(list + minIndex, &tmpN, sizeof(Node));
done++;
}
printf("%.2lf\n", sum);
if (times > 0) printf("\n");
}
return 0;
}