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

 

BOJ 14499번 주사위 굴리기 문제입니다.

 

처음에 인풋이 세로N, 가로M, 주사위가 놓인 위치 x y, 명령갯수 K가 주어지게 되는데,

N, M, x, y, K 순서 그대로 주어지는 건줄 알고 풀었다가 틀렸네요

N, M, y, x, K 순서로 보셔도 되고

N, M, x, y, K 순서로 보는 대신, N은 x축, M은 y축 으로 보셔도 되는 문제입니다.

 

게시판에 분명 이의제기가 있을 것 같아서 찾아 읽어보니,

백준님께서 x축, y축에 대한 언급이 없다는 설명이 맞는 말씀 같습니다.

헷갈릴수는 있지만, 문제없는 인풋입니다.

 

주사위는 문제에 각 위치를 전개도로 주었기 때문에, 이를 이용해서 동서남북에 대한 위치변경을 코드해주시면 되고

문제에서 요구하는대로 코드해주시면 문제없이 통과됩니다

 

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
#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[5];
 
int cube[7];
int arr[21][21];
int N, M, K;
queue<int> q;
 
void dfs(int y, int x, int cnt) {
    if (cnt == K) return;
 
    int yy, xx;
    int go;
    
    while (cnt<K) {
        cin >> go;
        cnt++;
        yy = y + direct[go].y;
        xx = x + direct[go].x;
        if (yy >= 0 && yy < N && xx >= 0 && xx < M) break;
        if (cnt == K) return;
    }
 
    if (go == 1) {
        int temp = cube[3];
        cube[3= cube[1];
        cube[1= cube[4];
        cube[4= cube[6];
        cube[6= temp;
    }
    if (go == 2) {
        int temp = cube[6];
        cube[6= cube[4];
        cube[4= cube[1];
        cube[1= cube[3];
        cube[3= temp;
    }
    if (go == 3) {
        int temp = cube[2];
        cube[2= cube[1];
        cube[1= cube[5];
        cube[5= cube[6];
        cube[6= temp;
    }
    if (go == 4) {
        int temp = cube[6];
        cube[6= cube[5];
        cube[5= cube[1];
        cube[1= cube[2];
        cube[2= temp;
    }
    if (arr[yy][xx] == 0) arr[yy][xx] = cube[6];
    else cube[6= arr[yy][xx], arr[yy][xx] = 0;
 
    cout << cube[1<< "\n";
    dfs(yy, xx, cnt);
}
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
    direct[1= { 0,1 };
    direct[2= { 0,-1 };
    direct[3= { -1,0 };
    direct[4= { 1,0 };
 
    int y, x;
    cin >> N >> M >> y >> x >> K;
 
    for (int i = 0; i < N; i++)
        for (int j = 0; j < M; j++)
            cin >> arr[i][j];
 
    dfs(y, x, 0);
 
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 1708번 볼록 껍질  (0) 2020.04.07
BOJ 1063번 킹  (0) 2020.04.07
BOJ 14503번 로봇 청소기  (0) 2020.03.13
BOJ 3709번 레이저빔은 어디로  (0) 2020.03.13
BOJ 1043번 거짓말  (0) 2020.03.13

+ Recent posts