-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7.cpp
64 lines (62 loc) · 1.79 KB
/
7.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
#include <bits/stdc++.h>
using namespace std;
int component[100][100];
int degree[100][100];
bool is_component[100];
void merge(int from, int to) {
is_component[from] = false;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (component[i][j] == from)
component[i][j] = to;
}
}
}
bool is_poly(int num) {
if (num <= 0)
return false;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (component[i][j] == num && degree[i][j]!=2)
return false;
}
}
return true;
}
int main() {
int x1, y1, x2, y2, component_num = 0, figures = 0;
for (int i = 0; i < 100; i++) {
is_component[i] = false;
for (int j = 0; j < 100; j++) {
component[i][j] = -1;
degree[i][j] = 0;
}
}
char c;
while (cin >> c >> x1 >> c >> y1 >> c >> c >> c >> x2 >> c >> y2 >> c >> c) {
int c1 = component[x1][y1], c2 = component[x2][y2];
degree[x1][y1]++;
degree[x2][y2]++;
// printf("(%d, %d), (%d, %d), %d, %d\n", x1,y1,x2,y2,c1,c2);
if (c1 == -1 && c2 == -1) {
component_num++;
component[x1][y1] = component_num;
component[x2][y2] = component_num;
is_component[component_num] = true;
figures++;
} else if (c1 == -1 && c2 > 0) {
component[x1][y1] = c2;
} else if (c1 > 0 && c2 == -1) {
component[x2][y2] = c1;
} else if (c1 > 0 && c2 > 0 && c1 != c2) {
merge(c1, c2);
figures--;
}
}
int poly = 0;
for (int i = 1; i <= component_num; i++) {
if (is_component[i] && is_poly(i))
poly++;
}
cout << figures << ' ' << poly << "\n";
}