-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3987.cpp
More file actions
119 lines (108 loc) · 1.56 KB
/
3987.cpp
File metadata and controls
119 lines (108 loc) · 1.56 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// 3987. 보이저 1호
// 2019.05.21
// 시뮬레이션
#include<iostream>
using namespace std;
int n, m;
int r, s;
int xx, yy, dir, ans, ansDir;
int visit[501][501][4];
char map[501][501];
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };
char out[4] = { 'U', 'R', 'D', 'L' };
bool flag = true;
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> map[i][j];
}
}
cin >> r >> s;
// 4가지 방향에 대해 조사
for (int i = 0; i < 4; ++i)
{
if (!flag)
{
break;
}
// 방향, 시작점 초기화
dir = i;
xx = r;
yy = s;
int count = 0;
while (1)
{
// 범위를 벗어날때
if (xx <= 0 || yy <= 0 || xx > n || yy > m)
{
break;
}
// 블랙홀일때
if (map[xx][yy] == 'C')
{
break;
}
// 이미방문한 곳일때
if (visit[xx][yy][dir])
{
flag = false;
break;
}
visit[xx][yy][dir] = 1;
// 방향전환
if (map[xx][yy] == '/')
{
if (dir == 0 || dir == 2)
{
dir++;
}
else
{
dir--;
}
}
if (map[xx][yy] == '\\')
{
if (dir == 0 || dir == 2)
{
dir--;
}
else
{
dir++;
}
dir = (dir + 4) % 4;
}
count++;
xx += dx[dir];
yy += dy[dir];
}
if (count > ans)
{
ans = count;
ansDir = i;
}
for (int j = 0; j < 501; j++)
{
for (int k = 0; k < 501; k++)
{
fill(visit[j][k], visit[j][k] + 4, 0);
}
}
}
cout << out[ansDir] << endl;
if (!flag)
{
cout << "Voyager" << endl;
}
else
{
cout << ans << endl;
}
return 0;
}