T-coding
백준 14499 주사위 굴리기 / Python 본문
728x90
728x90
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
코드
더보기
n, m, y, x, k = map(int, input().split())
dice = [0 for _ in range(6)]
arr = []
dy = [0, 0, -1, 1]
dx = [1, -1, 0, 0]
for _ in range(n):
arr.append(list(map(int, input().split())))
order = list(map(int, input().split()))
for i in order:
ny = y + dy[i - 1]
nx = x + dx[i - 1]
if 0 <= ny < n and 0 <= nx < m:
if i == 1:
dice[0], dice[5], dice[2], dice[4] = dice[5], dice[2], dice[4], dice[0]
elif i == 2:
dice[0], dice[4], dice[2], dice[5] = dice[4], dice[2], dice[5], dice[0]
elif i == 3:
dice[0], dice[3], dice[2], dice[1] = dice[3], dice[2], dice[1], dice[0]
elif i == 4:
dice[0], dice[1], dice[2], dice[3] = dice[1], dice[2], dice[3], dice[0]
if arr[ny][nx] != 0:
dice[2] = arr[ny][nx]
arr[ny][nx] = 0
else:
arr[ny][nx] = dice[2]
y = ny
x = nx
print(dice[0])
728x90
300x250
'Baekjoon' 카테고리의 다른 글
백준 15720 카우버거 / Python (0) | 2023.03.23 |
---|---|
백준 17413 단어 뒤집기 2 / Python (0) | 2023.03.22 |
백준 3190 뱀 / Python (0) | 2023.03.21 |
백준 14503 로봇 청소기 / Python (0) | 2023.03.21 |
백준 5567 결혼식 / Python (0) | 2023.03.21 |