BOJ::144499 주사위 굴리기

https://www.acmicpc.net/problem/14499


동서남북 방향에 대해 주사위 이동시 변화하는것만 잘 하면 된다.

코드 깔끔하게 짤 수 있을거 같은데 난 모르겠어서 무식하게 코딩했다.


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
#include <stdio.h>
using namespace std;
 
int dice[6= { 0,0,0,0,0,0 };
int map[20][20];
int dx[] = { 0,0,0,-1,1 };
int dy[] = { 0,1,-1,0,0 };
 
void move(int v) {
    if (v == 1) {
        int tmp = dice[1];
        dice[1= dice[5];
        dice[5= dice[3];
        dice[3= dice[2];
        dice[2= tmp;
    }
    else if (v == 2) {
        int tmp = dice[1];
        dice[1= dice[2];
        dice[2= dice[3];
        dice[3= dice[5];
        dice[5= tmp;
    }
    else if (v == 4) {
        int tmp = dice[0];
        dice[0= dice[2];
        dice[2= dice[4];
        dice[4= dice[5];
        dice[5= tmp;
    }
    else {
        int tmp = dice[0];
        dice[0= dice[5];
        dice[5= dice[4];
        dice[4= dice[2];
        dice[2= tmp;
    }
}
 
int main() {
    int n, m, x, y, k;
    scanf("%d %d %d %d %d"&n, &m, &x, &y, &k);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d"&map[i][j]);
        }
    }
    
    for (int i = 0; i < k; i++) {
        int v;
        scanf("%d"&v);
        x += dx[v];
        y += dy[v];
        if (x >= 0 && y >= 0 && x < n&&< m) {
            move(v);
            if (map[x][y] == 0) {
                map[x][y] = dice[5];
            }
            else {
                dice[5= map[x][y];
                map[x][y] = 0;
            }
            printf("%d\n", dice[2]);
        }
        else {
            x -= dx[v];
            y -= dy[v];
        }
    }
}
cs


'BOJ::문제풀이' 카테고리의 다른 글

9251 LCS  (0) 2018.01.14
14889 스타트와 링크  (0) 2018.01.14
11054 가장 긴 바이토닉 수열  (0) 2018.01.08
10159 저울  (0) 2018.01.08
14501 퇴사  (0) 2018.01.07

+ Recent posts