-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11561.cpp
More file actions
52 lines (51 loc) · 1.44 KB
/
Copy path11561.cpp
File metadata and controls
52 lines (51 loc) · 1.44 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
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
char a[200][200];
int N, M;
int call(int i, int j) {
int sum = 0;
if (i < 0 || j < 0 || i >= N || j >= M) return 0;
if (a[i][j] == '@' || a[i][j] == '#') return 0;
if (a[i][j] == 'G') sum = 1;
a[i][j] = '@';
for (int k = 0; k < 4; k++) {
if (i + dx[k] >= 0 && i + dx[k] < N && j + dy[k] >= 0 && j + dy[k] < M && a[i + dx[k]][j + dy[k]] == 'T') {
return sum;
}
}
for (int k = 0; k < 4; k++) {
sum += call(i + dx[k], j + dy[k]);
}
return sum;
}
int main() {
int n, m, i, j, k, tc, t = 1;
while (scanf("%d%d", &m, &n) == 2) {
getchar();
N = n;
M = m;
for (int i = 0; i < n; i++) gets(a[i]);
int count = 0;
int flag = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (a[i][j] == 'P') {
flag = 1;
for (k = 0; k < 4; k++)
if (i + dx[k] >= 0 && i + dx[k] < N && j + dy[k] >= 0 && j + dy[k] < M &&
a[i + dx[k]][j + dy[k]] == 'T') {
k = 0;
break;
}
k = call(i, j);
break;
}
}
if (flag == 1) break;
}
printf("%d\n", k);
}
return 0;
}