반응형
https://www.acmicpc.net/problem/14499
14499번: 주사위 굴리기
첫째 줄에 지도의 세로 크기 N, 가로 크기 M (1 ≤ N, M ≤ 20), 주사위를 놓은 곳의 좌표 x, y(0 ≤ x ≤ N-1, 0 ≤ y ≤ M-1), 그리고 명령의 개수 K (1 ≤ K ≤ 1,000)가 주어진다. 둘째 줄부터 N개의 줄에 지
www.acmicpc.net
주어진 조건에 맞게 구현을 하는 문제입니다.
주사위가 움직일 때 평면도의 어느부분이 어느곳으로 움직이는지를 신경써서 푸는 문제였습니다.
아래는 코드입니다.
더보기
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#include <iostream>
#include <queue>
using namespace std;
int board[20][20];
int dice[6] = { 0, 0, 0, 0, 0, 0 };
int N, M, x, y, K;
bool InRange(int x, int y)
{
return x >= 0 && x < N && y >= 0 && y < M;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> x >> y >> K;
queue<int> q;
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
cin >> board[i][j];
for (int i = 0; i < K; i++)
{
int num;
cin >> num;
q.push(num);
}
while (!q.empty())
{
int n = q.front();
int temp;
q.pop();
if (n == 1)
{
if (InRange(x, y + 1))
{
y++;
temp = dice[1];
dice[1] = dice[2];
dice[2] = dice[3];
dice[3] = dice[5];
dice[5] = temp;
if (board[x][y] == 0)
{
board[x][y] = dice[2];
}
else
{
dice[2] = board[x][y];
board[x][y] = 0;
}
cout << dice[5] << "\n";
}
}
else if (n == 2)
{
if (InRange(x, y - 1))
{
y--;
temp = dice[1];
dice[1] = dice[5];
dice[5] = dice[3];
dice[3] = dice[2];
dice[2] = temp;
if (board[x][y] == 0)
{
board[x][y] = dice[2];
}
else
{
dice[2] = board[x][y];
board[x][y] = 0;
}
cout << dice[5] << "\n";
}
}
else if (n == 3)
{
if (InRange(x - 1, y))
{
x--;
temp = dice[0];
dice[0] = dice[2];
dice[2] = dice[4];
dice[4] = dice[5];
dice[5] = temp;
if (board[x][y] == 0)
{
board[x][y] = dice[2];
}
else
{
dice[2] = board[x][y];
board[x][y] = 0;
}
cout << dice[5] << "\n";
}
}
else
{
if (InRange(x + 1, y))
{
x++;
temp = dice[0];
dice[0] = dice[5];
dice[5] = dice[4];
dice[4] = dice[2];
dice[2] = temp;
if (board[x][y] == 0)
{
board[x][y] = dice[2];
}
else
{
dice[2] = board[x][y];
board[x][y] = 0;
}
cout << dice[5] << "\n";
}
}
}
return 0;
}
|
cs |
반응형
'백준 문제풀이 > GOLD' 카테고리의 다른 글
[백준 / BOJ / GOLD 5] 5014 번 : 스타트링크 (0) | 2021.03.24 |
---|---|
[백준 / BOJ / GOLD 5] 16234 번 : 인구 이동 (0) | 2021.03.22 |
[백준 / BOJ / GOLD 5] 9019 번 : DSLR (0) | 2020.04.10 |
[백준 / BOJ / GOLD 4] 3055 번 : 탈출 (0) | 2020.04.01 |
[백준 / BOJ / GOLD 4] 13913 번 : 숨바꼭질 4 (0) | 2020.03.28 |