-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path백준-말이 되고픈 원숭이.cpp.txt
106 lines (94 loc) · 1.71 KB
/
백준-말이 되고픈 원숭이.cpp.txt
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include iostream
#includestack
#includestring
#includealgorithm
#includequeue
#includefunctional
using namespace std;
int K,W, H;
int arr[201][201];
int visit[201][201][31];
int dx[4] = { -1,1,0,0 };
int dy[4] = { 0,0,-1,1 };
int Hx[8] = { -2,-1,1,2,2,1,-1,-2 };
int Hy[8] = { 1,2,2,1,-1,-2,-2,-1 };
struct Monkey {
int x, y, depth, like_horse;
};
int main()
{
for (int i = 0; i 201; i++)
{
for (int j = 0; j 201; j++)
{
for (int t = 0; t 31; t++)
{
visit[i][j][t] = false;
}
}
}
cin K;
cin W H;
for (int i = 0; i H; i++)
{
for (int j = 0; j W; j++)
{
cin arr[i][j];
}
}
queueMonkey q;
Monkey mon;
mon.x = 0;
mon.y = 0;
mon.depth = 0;
mon.like_horse = 0;
visit[0][0][0] = true;
bool game_end = false;
q.push(mon);
while (!q.empty())
{
mon = q.front();
q.pop();
int x = mon.x;
int y = mon.y;
int depth = mon.depth;
int like_horse = mon.like_horse;
if (x == H - 1 && y == W - 1)
{
game_end = true;
cout depth endl;
break;
}
for (int i = 0; i 4; i++)
{
int Gx = x + dx[i];
int Gy = y + dy[i];
if (Gx = 0 && Gx H&&Gy = 0 && Gy W&&!visit[Gx][Gy][like_horse]&&arr[Gx][Gy]!=1)
{
visit[Gx][Gy][like_horse] = true;
mon.x = Gx;
mon.y = Gy;
mon.depth = depth + 1;
mon.like_horse = like_horse;
q.push(mon);
}
}
for (int i = 0; i 8; i++)
{
int Gx = x + Hx[i];
int Gy = y + Hy[i];
if (Gx = 0 && Gx H&&Gy = 0 && Gy W &&like_horseK&& !visit[Gx][Gy][like_horse+1] && arr[Gx][Gy] != 1)
{
visit[Gx][Gy][like_horse+1] = true;
mon.x = Gx;
mon.y = Gy;
mon.depth = depth + 1;
mon.like_horse = like_horse+1;
q.push(mon);
}
}
}
if (!game_end)
cout -1 endl;
return 0;
}