Hoon222y

[BOJ 14499] 주사위 굴리기 본문

코딩/BOJ & 알고스팟

[BOJ 14499] 주사위 굴리기

hoon222y 2017. 4. 11. 12:58

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
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
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
 
using namespace std;
 
int n,m,x,y,k,arr[5][5],visit[22][22],tmp;
bool chk(int a,int b)
    return a>0 && a<=&& b>0 && b<=m;
 
int main(){
    scanf("%d%d%d%d%d" , &n,&m,&y,&x,&k);
    x+=1;
    y+=1;
    memset(visit,0,sizeof(visit));
    
    arr[1][2= 0;
    arr[2][1= 0;
    arr[2][2= 0;
    arr[2][3= 0;
    arr[3][2= 0;
    arr[4][2= 0;
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d" , &visit[i][j]);
        }
    }
    
    queue<int> q;
    
    int t;
    
    while(k--){
        scanf("%d" , &t);
        if(t == 1){     //동
            if(chk(y,x+1)){
                if(visit[y][x+1== 0){
                    visit[y][x+1= arr[2][3];
                    tmp = arr[2][2];
                    arr[2][2= arr[2][1];
                    arr[2][1= arr[4][2];
                    arr[4][2= arr[2][3];
                    arr[2][3= tmp;
                    x+=1;
                }else{
                    tmp = arr[2][2];
                    arr[2][2= arr[2][1];
                    arr[2][1= arr[4][2];
                    arr[4][2= arr[2][3];
                    arr[2][3= tmp;
                    arr[4][2= visit[y][x+1];
                    visit[y][x+1= 0;
                    x+=1;
                }
                q.push(arr[2][2]);
            }
        }else if(t == 2){//서
            if(chk(y,x-1)){
                if(visit[y][x-1== 0){
                    visit[y][x-1= arr[2][1];
                    tmp = arr[2][2];
                    arr[2][2= arr[2][3];
                    arr[2][3= arr[4][2];
                    arr[4][2= arr[2][1];
                    arr[2][1= tmp;
                    x-=1;
                }else{
                    tmp = arr[2][2];
                    arr[2][2= arr[2][3];
                    arr[2][3= arr[4][2];
                    arr[4][2= arr[2][1];
                    arr[2][1= tmp;
                    arr[4][2= visit[y][x-1];
                    visit[y][x-1= 0;
                    x-=1;
                }
                q.push(arr[2][2]);
                
            }
        }else if(t == 3){// 북
            if(chk(y-1,x)){
                if(visit[y-1][x] == 0){
                    visit[y-1][x] = arr[1][2];
                    tmp = arr[2][2];
                    arr[2][2= arr[3][2];
                    arr[3][2= arr[4][2];
                    arr[4][2= arr[1][2];
                    arr[1][2= tmp;
                    y-=1;
                }else{
                    tmp = arr[2][2];
                    arr[2][2= arr[3][2];
                    arr[3][2= arr[4][2];
                    arr[4][2= arr[1][2];
                    arr[1][2= tmp;
                    arr[4][2= visit[y-1][x];
                    visit[y-1][x] = 0;
                    y-=1;
                }
                q.push(arr[2][2]);
            }
        }else if(t == 4){    //남
            if(chk(y+1,x)){
                
                if(visit[y+1][x] == 0){
                    visit[y+1][x] = arr[3][2];
                    tmp = arr[2][2];
                    arr[2][2= arr[1][2];
                    arr[1][2= arr[4][2];
                    arr[4][2= arr[3][2];
                    arr[3][2= tmp;
                    y+=1;
                }else{
                    tmp = arr[2][2];
                    arr[2][2= arr[1][2];
                    arr[1][2= arr[4][2];
                    arr[4][2= arr[3][2];
                    arr[3][2= tmp;
                    arr[4][2= visit[y+1][x];
                    visit[y+1][x] = 0;
                    y+=1;
                }
                q.push(arr[2][2]);
            }
        }
    }
    while(!q.empty()){
        printf("%d ",q.front());
        q.pop();
    }
    
    
    return 0;
}
cs


그렇다 .. 노가다 구현 ㅋㅋㅋㅋㅋ dx[],dy[] 배열 쓰면 더 깔끔할꺼 같은데 귀찮으니까 패스

'코딩 > BOJ & 알고스팟' 카테고리의 다른 글

[BOJ 1182] 부분집합의 합  (0) 2017.05.25
[BOJ 1261] 알고스팟  (0) 2017.05.24
[BOJ 13460] 째로탈출2  (0) 2017.04.11
[BOJ 2206] 벽 부수고 이동하기  (1) 2017.04.07
[BOJ 1613] 역사  (1) 2017.03.28
Comments