-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10026.cpp
More file actions
71 lines (64 loc) · 1.18 KB
/
Copy path10026.cpp
File metadata and controls
71 lines (64 loc) · 1.18 KB
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
#include <cstdio>
#include <queue>
using namespace std;
int n;
char a[101][101], b[101][101];
int dx[] = { 1,-1,0,0 };
int dy[] = { 0,0,1,-1 };
queue<pair<int, int>> q;
bool visited[101][101];
char c;
void sol(char array[][101]) {
int t = 0;
int x, y;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (visited[i][j])
continue;
else {
q.push({ j,i });
t++;
c = array[i][j];
while (!q.empty()) {
x = q.front().first;
y = q.front().second;
q.pop();
if (visited[y][x])
continue;
visited[y][x] = true;
for (int i = 0, px, py; i < 4; i++) {
px = dx[i] + x;
py = dy[i] + y;
if (px<1 || px>n || py<1 || py>n)
continue;
if (visited[py][px])
continue;
if (array[py][px] == c)
q.push({ px,py });
}
}
}
}
}
printf("%d ", t);
}
int main() {
scanf("%d", &n);
scanf("%c", &c);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%c", &c);
a[i][j] = c;
if (c == 'G')
c = 'R';
b[i][j] = c;
}
scanf("%c", &c);
}
sol(a);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
visited[i][j] = false;
sol(b);
return 0;
}