BOJ : https://www.acmicpc.net/problem/3709
시뮬레이션 기본문제 입니다.
난이도는 높은편이 아니라서 문제에서 요구하는 대로 구현해주시면 됩니다.
설명이 필요할 것 같은 부분?은 주석처리했습니다.
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
|
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <cmath>
#include <limits>
#include <cstring>
using namespace std;
struct direct {
int y, x;
}direct[4];
bool arr[52][52];
int n, r;
void dfs(int y, int x, int dt) {
if (!y || !x || y == n + 1 || x == n + 1) {
cout << y << " " << x << '\n';
return;
}
// 꺽이면
if (arr[y][x]) {
int go = (dt + 1) % 4;
dfs(y + direct[go].y, x + direct[go].x, go);
}
else {
dfs(y + direct[dt].y, x + direct[dt].x, dt);
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// 방향조절 (동->남->서->북)
direct[0] = { 0,1 };
direct[1] = { 1,0 };
direct[2] = { 0,-1 };
direct[3] = { -1,0 };
int T; cin >> T;
while (T--) {
memset(arr, 0, sizeof(arr));
cin >> n >> r;
for (int i = 0; i < r; i++) {
int x, y;
cin >> y >> x;
arr[y][x] = true;
}
int sy, sx;
cin >> sy >> sx;
// 위 -> 아래
if (sy == 0) dfs(sy + 1, sx, 1);
// 아래 -> 위
if (sy == n + 1) dfs(sy - 1, sx, 3);
// 왼쪽 -> 오른쪽
if (sx == 0) dfs(sy, sx + 1, 0);
// 오른쪽 -> 왼쪽
if (sx == n + 1) dfs(sy, sx - 1, 2);
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
BOJ 14499번 주사위 굴리기 (0) | 2020.03.14 |
---|---|
BOJ 14503번 로봇 청소기 (0) | 2020.03.13 |
BOJ 1043번 거짓말 (0) | 2020.03.13 |
BOJ 1074번 Z (0) | 2020.03.05 |
BOJ 1026번 보물 (0) | 2020.02.28 |