/
10301.cpp
50 lines (41 loc) · 1.2 KB
/
10301.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 <iostream>
#define sq(a) ((a)*(a))
using namespace std;
struct circle {
double x, y, r;
};
bool intercept(circle &c1, circle &c2) {
long double r1 = sq(c1.r - c2.r), r2 = sq(c1.r + c2.r);
long double dist = sq(c1.x - c2.x) + sq(c1.y - c2.y);
return dist >= r1 and dist <= r2;
}
int sets[101], n;
circle circles[101];
int findSet(int a) { while(sets[a] != a) a = sets[a]; return a; }
void unionSet(int a, int b) {
int sa = findSet(a), sb = findSet(b);
for (int i = 0; i < n; i++)
if (sets[i] == sa) sets[i] = sb;
}
int main() {
while (cin >> n) {
if (n == -1) return 0;
for (int i = 0; i < n; i++) sets[i] = i;
for (int i = 0; i < n; i++) {
cin >> circles[i].x >> circles[i].y >> circles[i].r;
for (int j = 0; j < i; j++)
if (intercept(circles[j], circles[i])) unionSet(j, i);
}
int mcount = 0;
for (int i = 0; i < n; i++) {
int count = 0;
for (int j = 0; j < n; j++)
if (sets[j] == i) count++;
mcount = max(count, mcount);
}
if (mcount == 1)
cout << "The largest component contains " << mcount << " ring." << endl;
else
cout << "The largest component contains " << mcount << " rings." << endl;
}
}