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
- 문제풀이
- SQL
- 코테
- 프로그래머스
- 운동기록
- 문자열
- binary search
- SWEA
- greedy
- dfs
- priorityqueue
- MySQL
- 시뮬레이션
- oracle
- 러닝일지
- 백준
- 문제해결
- 투포인터
- Java
- BOJ
- db
- COS PRO
- DP
- BFS
- 알고리즘
- 자바
Archives
- Today
- Total
슈콩
[BOJ] 백준 14499 주사위 굴리기 본문
[문제]
https://www.acmicpc.net/problem/14499
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int n,m,x,y;
static int[][] map;
static int[] dice;
static int[] dr = {0,0,-1,1};
static int[] dc = {1,-1,0,0};
static int[][] info = {
{2,0,3,5},
{3,0,2,5},
{1,0,4,5},
{5,4,0,1}
};
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());
x = Integer.parseInt(st.nextToken());
y = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
dice = new int[6];
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());
for(int i=0;i<k;i++) {
int dir = Integer.parseInt(st.nextToken()) - 1;
if(!move(dir)) continue;
System.out.println(dice[0]);
}
}
private static boolean move(int dir) {
int nr = x + dr[dir];
int nc = y + dc[dir];
if(nr<0 || nr>=n || nc<0 || nc>=m) return false;
int[] temp = dice.clone();
for(int i=0;i<4;i++) {
dice[info[dir][i]] = temp[info[dir][(i+1)%4]];
}
if(map[nr][nc]==0) {
map[nr][nc] = dice[5];
}
else {
dice[5] = map[nr][nc];
map[nr][nc] = 0;
}
x = nr; y = nc;
return true;
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백주 1822 차집합 (0) | 2025.09.19 |
|---|---|
| [BOJ] 백준 14502 연구소 (2) | 2025.09.19 |
| [BOJ] 백준 16401 과자 나눠주기 (0) | 2025.09.18 |
| [BOJ] 백준 14921 용액 합성하기 (0) | 2025.09.18 |
| [BOJ] 백준 13460 구슬 탈출 2 (2) | 2025.09.18 |