티스토리 뷰

백준 :: BOJ :: 14499 :: 주사위 굴리기


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


#include <bits/stdc++.h>

using namespace std;


int N, M, x, y, K;

int arr[20][20];

vector<int>dice = { 0,0,0,0,0,0 };

int dx[] = {0,1,-1,0,0}, dy[] = {0,0,0,-1,1};


inline bool check(int i, int j) { return i >= 0 && j >= 0 && i < N && j < M ? true : false; }


void Rolling(int d) {

vector<int>tmp(dice);

if (d == 1) {

dice[0] = tmp[3]; dice[2] = tmp[0]; dice[3] = tmp[5]; dice[5] = tmp[2];

}

else if (d == 2) {

dice[0] = tmp[2]; dice[2] = tmp[5]; dice[3] = tmp[0]; dice[5] = tmp[3];

}

else if (d == 3) {

dice[1] = tmp[0]; dice[0] = tmp[4]; dice[4] = tmp[5]; dice[5] = tmp[1];

}

else {

dice[1] = tmp[5]; dice[0] = tmp[1]; dice[4] = tmp[0]; dice[5] = tmp[4];

}

}


int main() {

std::ios::sync_with_stdio(false);cin.tie(0);

cin >> N >> M >> y >> x >> K; vector<int> order(K);

for (int i = 0;i < N;i++) for (int j = 0; j < M; j++) cin >> arr[i][j];

for (int i = 0; i < K; i++) cin >> order[i];

for (int k = 0; k < K; k++) {

if (check(y + dy[order[k]], x + dx[order[k]])) {

y += dy[order[k]]; x += dx[order[k]]; Rolling(order[k]);

if (arr[y][x]) {

dice[5] = arr[y][x]; arr[y][x] = 0;

}

else arr[y][x] = dice[5];

cout << dice[0] << '\n';

}

}


return 0;

}


'알고리즘 > BOJ' 카테고리의 다른 글

[BOJ 15686] 치킨 배달  (0) 2018.10.08
[BOJ 15685] 드래곤 커브  (0) 2018.10.07
[BOJ 7576] 토마토  (0) 2018.10.02
[BOJ 2178] 미로탐색  (0) 2018.10.02
[BOJ 2468] 안전 영역  (0) 2018.09.18
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함