# BZOJ1821: [JSOI2010]Group 部落划分 Group

## 1821: [JSOI2010]Group 部落划分 Group

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 3099  Solved: 1467
[Submit][Status][Discuss]

4 2
0 0
0 1
1 1
1 0

1.00

## Source

1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cstdlib>
5 #include <algorithm>
6 #include <cmath>
7 #include <queue>
8 #include <vector>
9 #define min(a, b) ((a) < (b) ? (a) : (b))
10 #define max(a, b) ((a) > (b) ? (a) : (b))
11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
12 inline void swap(int &a, int &b)
13 {
14     int tmp = a;a = b;b = tmp;
15 }
17 {
18     x = 0;char ch = getchar(), c = ch;
19     while(ch < 0 || ch > 9) c = ch, ch = getchar();
20     while(ch <= 9 && ch >= 0) x = x * 10 + ch - 0, ch = getchar();
21     if(c == -)x = -x;
22 }
23
24 const int INF = 0x3f3f3f3f;
25 const int MAXN = 1000 + 10;
26
27 int n, k, tot, cnt[MAXN * MAXN], u[MAXN * MAXN], v[MAXN * MAXN], x[MAXN], y[MAXN], fa[MAXN];
28 int w[MAXN * MAXN];
29
30 int find(int x)
31 {
32     return x == fa[x] ? x : fa[x] = find(fa[x]);
33 }
34
35 bool cmp(int a, int b)
36 {
37     return w[a] < w[b];
38 }
39
40 int main()
41 {
43     for(register int i = 1;i <= n;++ i)
45     for(register int i = 1;i <= n;++ i)
46         for(register int j = i + 1;j <= n;++ j)
47         {
48             ++ tot;
49             u[tot] = i, v[tot] = j, cnt[tot] = tot;
50             w[tot] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
51         }
52     std::sort(cnt + 1, cnt + 1 + tot, cmp);
53     for(register int i = 1;i <= tot;++ i)
54     {
55         int f1 = find(u[cnt[i]]), f2 = find(v[cnt[i]]);
56         if(f1 == f2) continue;
57         fa[f1] = f2;
58         -- n;
59         if(n == k - 1)
60         {
61             printf("%.2lf", sqrt(w[cnt[i]]));
62             return 0;
63         }
64     }
65     return 0;
66 }
BZOJ1821

BZOJ1821: [JSOI2010]Group 部落划分 Group

(0)
(0)

0条