Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 프로그래머스
- math
- 문자열
- DP
- 시뮬레이션
- 운동기록
- BOJ
- 백준
- 문제해결
- db
- binary search
- SQL
- 코테
- priorityqueue
- greedy
- 러닝일지
- 알고리즘
- 문제풀이
- 자바
- dfs
- SWEA
- COS PRO
- 코딩테스트
- BFS
- MySQL
- 건강
- 투포인터
- 이분탐색
- Java
- oracle
Archives
- Today
- Total
슈콩
[BOJ] 14499 주사위 굴리기 본문


[문제]
https://www.acmicpc.net/problem/14499
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int[] dr = {0,0,0,-1,1};
static int[] dc = {0,1,-1,0,0};
static int[] dice = new int[6];
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[][] map = new int[n][m];
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());
}
}
st = new StringTokenizer(br.readLine());
while(k-->0) {
int dir = Integer.parseInt(st.nextToken());
int nr = x + dr[dir];
int nc = y + dc[dir];
if(nr<0 || nr>=n || nc<0 || nc>=m) continue;
rotate(dir);
if(map[nr][nc]==0) map[nr][nc] = dice[5];
else {
dice[5] = map[nr][nc];
map[nr][nc] = 0;
}
x = nr; y = nc;
System.out.println(dice[0]);
}
}
private static void rotate(int dir) {
int[] temp = new int[6];
temp = dice.clone();
if(dir==1) {
int tmp = dice[0];
dice[0] = temp[3];
dice[3] = temp[5];
dice[5] = temp[2];
dice[2] = tmp;
}
else if(dir==2) {
int tmp = dice[0];
dice[0] = temp[2];
dice[2] = temp[5];
dice[5] = temp[3];
dice[3] = tmp;
}
else if(dir==3) {
int tmp = dice[1];
dice[1] = temp[0];
dice[0] = temp[4];
dice[4] = temp[5];
dice[5] = tmp;
}
else {
int tmp = dice[5];
dice[5] = temp[4];
dice[4] = temp[0];
dice[0] = temp[1];
dice[1] = tmp;
}
}
}
회전 : 기준 값에서 회전되는 값 확인 (공간 추론)
'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 14501 퇴사 (0) | 2025.12.01 |
|---|---|
| [BOJ] 14500 테트로미노 (0) | 2025.12.01 |
| [BOJ] 13458 시험 감독 (0) | 2025.11.30 |
| [BOJ] 3190 뱀 (0) | 2025.11.30 |
| [BOJ] 12100 2024(Easy) (0) | 2025.11.30 |