[BOJ] 13901 로봇

Time Lapse :None

13901.cpp

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
#include <stdio.h>
#include <queue>
using namespace std;
int map[1000][1000];
int N, M, K, y, x;
int dir[4], dpos;
int dx[4] = { 0,0,-1,1 };
int dy[4] = { -1,1,0,0 };
int main() {
scanf("%d %d %d", &N, &M, &K);
for (int i = 0; i < K; ++i) {
scanf("%d %d", &y, &x);
map[y][x] = 1;
}
scanf("%d %d", &y, &x);
map[y][x] = 1;
for (int i = 0; i < 4; ++i)
scanf("%d", &dir[i]), --dir[i];
int flag = 0;
while (flag < 4) {
flag = 0;
for (int i = 0; i < 4; ++i) {
int nx = x + dx[dir[dpos]];
int ny = y + dy[dir[dpos]];
if (0 <= nx && nx < M && 0 <= ny && ny < N && !map[ny][nx]) {
map[ny][nx] = 1;
x = nx, y = ny;
break;
}
else {
dpos = (dpos + 1) % 4;
++flag;
}
}
}
printf("%d %d", y, x);

}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/13901/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.