Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
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
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[BAEKJOON] 14499. 주사위 굴리기 본문

acmicpc

[BAEKJOON] 14499. 주사위 굴리기

코드와이 2021. 5. 20. 01:35

 

문제링크

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

 

package acmicpc.Gold5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class 주사위_굴리기 {

	static int n, m, r, c, k, map[][], dice[];
	static int[] dr = {0,0,0,-1,1};
	static int[] dc = {0,1,-1,0,0};
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		r = Integer.parseInt(st.nextToken());
		c = Integer.parseInt(st.nextToken());
		k = Integer.parseInt(st.nextToken());
		
		map = new int[n][m];
		dice = new int[6];
		for(int i = 0 ; i < n ; i++) {
			st = new StringTokenizer(br.readLine());
			for(int j = 0 ; j < m ; j++) {
				map[i][j] = Integer.parseInt(st.nextToken());
			}
		}
		dice = new int[6];
		st = new StringTokenizer(br.readLine());
		for(int i = 0 ; i < k ; i++) {
			int x = Integer.parseInt(st.nextToken());
			
			r += dr[x];
			c += dc[x];
			
			if(r < 0 || c < 0 || r >= n || c >= m) {
				r -= dr[x];
				c -= dc[x];
				continue;
			}
			go(x);
			
			if(map[r][c] == 0) {
				map[r][c] = dice[5];
			} else {
				dice[5] = map[r][c];
				map[r][c] = 0;
			}
			
			System.out.println(dice[0]);
		}
		
		
		
	}
	
	public static void go(int d) {
		int[] tmp = dice.clone();
		
		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[0] = tmp[4];
			dice[1] = tmp[0];
			dice[4] = tmp[5];
			dice[5] = tmp[1];
		} else if( d == 4 ) {
			dice[0] = tmp[1];
			dice[1] = tmp[5];
			dice[4] = tmp[0];
			dice[5] = tmp[4];
		}
	}
}

'acmicpc' 카테고리의 다른 글

[BAEKJOON] 1107. 리모컨  (0) 2021.05.27
[BAEKJOON] 14891. 톱니바퀴  (0) 2021.05.21
[BAEKJOON] 3190. 뱀  (0) 2021.05.18
[BAEKJOON] 7453. 합이 0인 네 정수  (0) 2021.05.16
[BAEKJOON] 1525. 퍼즐  (0) 2021.05.13