-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetOutOfDg.cpp
More file actions
84 lines (70 loc) · 1.69 KB
/
getOutOfDg.cpp
File metadata and controls
84 lines (70 loc) · 1.69 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
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <bits/stdc++.h>
using namespace std;
struct Step
{
int x;
int y;
};
Step step[51];
char dg[51][51];
int mark[51][51];
bool lev = false;
int n, m, x, y, k;
bool isClear(int x, int y,
int nx, int ny)
{
bool res1 = true;
bool res2 = true;
{
for (int i = x; i <= nx; i++)
if (dg[i][y] == 'X')
res1 = false;
for (int j = y; j <= ny; j++)
if (dg[nx][j] == 'X')
res1 = false;
}
{
for (int j = y; j <= ny; j++)
if (dg[x][j] == 'X')
res2 = false;
for (int i = x; i <= nx; i++)
if (dg[i][ny] == 'X')
res2 = false;
}
return res1 | res2;
}
void moving(int x, int y, int num)
{
mark[x][y] = num;
cout << "current path : " << x << " " << y << " " << endl;
for (int i = 0; i < k; i++) {
int nx = step[i].x + x;
int ny = step[i].y + y;
if (nx >= 0 && nx < n &&
ny >= 0 && ny < m &&
mark[nx][ny] > num+1)
if (isClear(x, y, nx, ny))
moving(nx, ny, num+1);
}
}
int main()
{
int res = -1;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> dg[i][j];
cin >> x >> y >> k;
for (int i = 0; i < k; i++)
cin >> step[i].x >> step[i].y;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
mark[i][j] = INT_MAX;
moving(x, y, 0);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (mark[i][j] != INT_MAX && mark[i][j] > res)
res = mark[i][j];
cout << res;
return 0;
}