설명없음

백준 14499: 주사위 굴리기 [C언어], 삼성 코딩 테스트

치킨먹고싶어요 2022. 6. 13. 13:28

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

#include <stdio.h>
 
int dy[4= {00-11};
int dx[4= {1-100};
int N, M, Y, X, K; 
int map[20][20], order[1000]; int dice[5][4]; int tmp[5][4];
 
void input(){
    scanf("%d %d %d %d %d",&N, &M, &Y, &X, &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++) { scanf("%d", order + i); order[i]--; };
}
 
void roll(int n){
    if (n == 1){
        tmp[1][2= dice[1][2]; tmp[3][2= dice[3][2];
        tmp[2][1= dice[2][2]; tmp[2][2= dice[2][3]; tmp[2][3= dice[4][2];
        tmp[4][2= dice[2][1];
        for (int j = 1; j <= 4; j++) {
            for (int k = 1; k <= 3; k++){
                dice[j][k] = tmp[j][k];   
            }
        }
    }
    else if (n == 2) {
        tmp[1][2= dice[1][2]; tmp[3][2= dice[3][2];
        tmp[2][1= dice[4][2]; tmp[2][2= dice[2][1]; tmp[2][3= dice[2][2];
        tmp[4][2= dice[2][3];
        for (int j = 1; j <= 4; j++) {
            for (int k = 1; k <= 3; k++){
                dice[j][k] = tmp[j][k];   
            }
        }
    }
    else if (n == 3) {
        tmp[1][2= dice[4][2];
        for (int i = 1; i <= 3; i++) tmp[i + 1][2= dice[i][2];
        for (int i = 1; i <= 4; i++) dice[i][2= tmp[i][2];
    }
    else {
        tmp[4][2= dice[1][2];
        for (int i = 2; i <= 4; i++) tmp[i - 1][2= dice[i][2];
        for (int i = 1; i <= 4; i++) dice[i][2= tmp[i][2];
    }
}
 
void solve(){
    for (int i = 0; i < K; i++) {
        if (Y + dy[order[i]] >= 0 && Y + dy[order[i]] < N && X + dx[order[i]] >= 0 && X + dx[order[i]] < M) {
            Y = Y + dy[order[i]]; X = X + dx[order[i]];
            roll(order[i] + 1);
            if (!map[Y][X]) map[Y][X] = dice[2][2];
            else {
                dice[2][2= map[Y][X]; 
                map[Y][X] = 0;
            }
            printf("%d\n", dice[4][2]);
        }
    }
}
 
int main(void) {
    input(); solve();
    return 0;
}
cs