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
#include <iostream>
using namespace std;
int N, M, x, y, K;
int MAP[20][20];
int oper[1001];
int num_dice[7= { 00,0,0,0,0,0 };
// 1    2    3        4    5      6 
// 윗면 앞면 오른쪽면 뒷면 왼쪽면 바닥면
int dice[7]=0,1,5,3,2,4,6 };
int dx[5= { 00,0,-1,1 };
int dy[5= { 01,-1,0,0 };
void oper_1() {
    int temp1 = dice[1]; // 윗면
    int temp2 = dice[3]; // 오른쪽면
    int temp3 = dice[5]; // 왼쪽면
    int temp4 = dice[6]; // 바닥면
    dice[1= temp3;
    dice[3= temp1;
    dice[5= temp4;
    dice[6= temp2;
}
void oper_2() {
    int temp1 = dice[1]; // 윗면
    int temp2 = dice[3]; // 오른쪽면
    int temp3 = dice[5]; // 왼쪽면
    int temp4 = dice[6]; // 바닥면
    dice[1= temp2;
    dice[3= temp4;
    dice[5= temp1;
    dice[6= temp3;
}
void oper_3() {
    int temp1 = dice[1]; // 위
    int temp2 = dice[2]; // 앞
    int temp3 = dice[6]; // 바닥
    int temp4 = dice[4]; // 뒷면
    dice[1= temp2;
    dice[2= temp3;
    dice[6= temp4;
    dice[4= temp1;
}
void oper_4() {
    int temp1 = dice[1]; // 위
    int temp2 = dice[2]; // 앞
    int temp3 = dice[6]; // 바닥
    int temp4 = dice[4]; // 뒷면
    dice[1= temp4;
    dice[2= temp1;
    dice[6= temp2;
    dice[4= temp3;
}
void find() {
    for (int i = 1; i <= K; i++) {
        int next_x = x + dx[oper[i]];
        int next_y = y + dy[oper[i]];
        if (next_x >= 0 && next_x <= N - 1 && next_y >= 0 && next_y <= M - 1) {
            //cout << "oper : "<< oper[i] << endl;
            if (oper[i] == 1)
                oper_1();
            else if (oper[i] == 2)
                oper_2();
            else if (oper[i] == 3)
                oper_3();
            else if (oper[i] == 4)
                oper_4();
            if (MAP[next_x][next_y] == 0) {
                MAP[next_x][next_y] = num_dice[dice[6]];
                cout << num_dice[dice[1]] << "\n";
            }
            else {
                num_dice[dice[6]] = MAP[next_x][next_y];
                MAP[next_x][next_y] = 0;
                cout << num_dice[dice[1]] << "\n";
            }
            x = next_x;
            y = next_y;
        }
        else
            continue;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M;
    cin >> x >> y >> K;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> MAP[i][j];
        }
    }
    for (int i = 1; i <= K; i++)
        cin >> oper[i];
 
    find();
}
cs

'BAEKJOON ONLINE JUDGE' 카테고리의 다른 글

[백준 20061] 모노미노도미노 2 (C++)  (0) 2021.08.23
[백준 21609] 상어 중학교 (C++)  (0) 2021.08.22
[백준 3190] 뱀 (C++)  (0) 2021.08.21
[백준 1092] 배 (C++)  (0) 2021.08.21
[백준 19237] 어른 상어 (C++)  (0) 2021.08.21

+ Recent posts