-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathundetected.cpp
80 lines (60 loc) · 1.61 KB
/
undetected.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
using namespace std;
struct DisjointSets {
DisjointSets(int n) : parent(n), rank(n, 0) { iota(parent.begin(), parent.end(), 0); }
int find(const int u) {
if (u != parent[u]) parent[u] = find(parent[u]);
return parent[u];
}
void merge(int x, int y) {
x = find(x), y = find(y);
if (rank[x] > rank[y])
parent[y] = x;
else
parent[x] = y;
if (rank[x] == rank[y]) rank[y]++;
}
private:
vector<int> parent, rank;
};
struct Circle {
double x, y, r;
bool intersects(const Circle& c) const {
const double center_dist = hypot(x - c.x, y - c.y);
const double radius_sum = r + c.r;
return center_dist < radius_sum;
}
} circles[201];
const int X = 200;
bool can_cross(const int K) {
DisjointSets ds(K);
for (int i = 0; i < K; i++)
for (int j = i + 1; j < K; j++)
if (circles[i].intersects(circles[j])) ds.merge(i, j);
vector<int> out_left, out_right;
for (int i = 0; i < K; i++) {
const int min_x = circles[i].x - circles[i].r;
const int max_x = circles[i].x + circles[i].r;
if (min_x < 0) {
out_left.push_back(i);
for (const int r : out_right)
if (ds.find(r) == ds.find(i)) return false;
}
if (X < max_x) {
out_right.push_back(i);
for (const int l : out_left)
if (ds.find(l) == ds.find(i)) return false;
}
}
return true;
}
int main() {
int N;
while (cin >> N) {
for (int i = 0; i < N; i++) cin >> circles[i].x >> circles[i].y >> circles[i].r;
int ans = 0;
for (int k = 1; k <= N; k++)
if (can_cross(k)) ans = k;
cout << ans << endl;
}
}