-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11561_gettinggold.cpp
More file actions
59 lines (59 loc) · 1.17 KB
/
Copy path11561_gettinggold.cpp
File metadata and controls
59 lines (59 loc) · 1.17 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
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
using namespace std;
#define size 51
#define valid(nx,ny) nx>=0 && nx<H && ny>=0 && ny<W
char Grid[size][size];
int Used[size][size];
int Sx, Sy;
int H, W;
int Ans;
int fx[] = { 0, 0, -1, 1 };
int fy[] = { 1, -1, 0, 0 };
void solve(int sx, int sy){
int gold;
//printf("at (%d,%d)gold %d\n",sx,sy,Ans);
int nx, ny;
if (Grid[sx][sy] == 'G')
{
Ans += 1;
Grid[sx][sy] = '.';
}
if (Grid[sx][sy + 1] == 'T' || Grid[sx + 1][sy] == 'T' || Grid[sx - 1][sy] == 'T' || Grid[sx][sy - 1] == 'T'){
//Ans = gold;
//printf("-----------\n");
return;
}
for (int i = 0; i < 4; i++)
{
nx = sx + fx[i];
ny = sy + fy[i];
if (valid(nx, ny) && Grid[nx][ny] != '#' && Used[nx][ny] == 0)
{
Used[nx][ny] = 1;
solve(nx, ny);
//Used[nx][ny] = 0;
}
}
}
int main(){
freopen("input.txt", "r", stdin);
int i, j;
while (cin >> W >> H){
for (i = 0; i < H; i++){
for (j = 0; j < W; j++){
cin >> Grid[i][j];
Used[i][j] = 0;
if (Grid[i][j] == 'P')
{
Sx = i;
Sy = j;
}
}
}
Ans = 0;
solve(Sx, Sy);
cout << Ans << endl;
}
}