-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path469.cpp
More file actions
62 lines (59 loc) · 1.35 KB
/
469.cpp
File metadata and controls
62 lines (59 loc) · 1.35 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
#include <bits/stdc++.h>
using namespace std;
char a[200][200];
char c[200][200];
int N, M;
int dirx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[] = {0, -1, 1, 0, -1, 1, -1, 1};
int call(int i, int j) {
if (i < 0 || j < 0 || i >= N || j >= M) return 0;
if (c[i][j] != 'W') return 0;
c[i][j] = 'L';
int sum = 1;
for (int k = 0; k < 8; k++) {
sum += call(i + dirx[k], j + diry[k]);
}
return sum;
}
void copy(void) {
int i, j;
for (i = 0; i < N; i++) {
strcpy(c[i], a[i]);
}
}
int main() {
int tc, flag = 0;
cin >> tc;
getchar();
getchar();
while (tc--) {
if (flag != 0) puts("");
flag = 1;
int i = 0, j;
while (gets(a[i])) {
if (a[i][0] != 'L' && a[i][0] != 'W') break;
i++;
}
N = i;
M = strlen(a[0]);
sscanf(a[i], "%d %d", &i, &j);
int sum = 0;
if (i - 1 < N && j - 1 < M) {
copy();
sum = call(i - 1, j - 1);
}
printf("%d\n", sum);
char b[20];
while (gets(b)) {
if (strlen(b) == 0) break;
sscanf(b, "%d %d", &i, &j);
sum = 0;
if (i - 1 < N && j - 1 < M) {
copy();
sum = call(i - 1, j - 1);
}
printf("%d\n", sum);
}
}
return 0;
}