이동할 때마다 주사위의 윗 면에 쓰여 있는 수를 출력하기
2
4 1 3
5
5
입력 | 출력 |
---|---|
4 2 0 0 8 0 2 3 4 5 6 7 8 4 4 4 1 3 3 3 2 | 0 0 3 0 0 8 6 3 |
3 3 1 1 9 1 2 3 4 0 5 6 7 8 1 3 2 2 4 4 1 1 3 | 0 0 0 3 0 1 0 6 0 |
2 2 0 0 16 0 2 3 4 4 4 4 4 1 1 1 1 3 3 3 3 2 2 2 2 | 0 0 0 0 |
3 3 0 0 16 0 1 2 3 4 5 6 7 8 4 4 1 1 3 3 2 2 4 4 1 1 3 3 2 2 | 0 0 0 6 0 8 0 2 0 8 0 2 0 8 0 2 |
: 문제 이해를 잘못해서 1~6까지의 모든 면이 가장 위에 있을 때 동서남북으로 이동하면 몇번 면이 되는지를 구하는 건줄 알았다.
주사위 윗면 : dice[1], 주사위 아랫면 : dice[6]으로 고정.
- 초기 주사위 상태에서(1이 가장 윗면) 계속 동쪽으로 : 1->3->6->4->1
- 즉, 1->3, 3->6, 6->4, 4->1
- 초기 주사위 상태에서 계속 서쪽 : 1->4->6->3->1
- 초기 주사위 상태에서 계속 남쪽 : 1->2->6->5->1
- 초기 주사위 상태에서 계속 북쪽 : 1->5->6->2->1
def move(c):
if c == 1:
dice[1], dice[3], dice[6], dice[4] = dice[3], dice[6], dice[4], dice[1]
elif c == 2:
dice[1], dice[4], dice[6], dice[3] = dice[4], dice[6], dice[3], dice[1]
elif c == 3:
dice[1], dice[5], dice[6], dice[2] = dice[5], dice[6], dice[2], dice[1]
elif c == 4:
dice[1], dice[2], dice[6], dice[5] = dice[2], dice[6], dice[5], dice[1]
n, m, x, y, k = map(int, input().split())
maps = [list(map(int, input().split())) for _ in range(n)]
arr = list(map(int, input().split()))
dice = [0, 0, 0, 0, 0, 0, 0]
command = {1:(0,1), 2:(0,-1), 3:(-1,0), 4:(1,0)}
for c in arr:
dx, dy = command[c]
nx = x + dx
ny = y + dy
if 0<=nx<n and 0<=ny<m:
move(c)
if maps[nx][ny] == 0:
maps[nx][ny] = dice[6]
else:
dice[6] = maps[nx][ny]
maps[nx][ny] = 0
x, y = nx, ny
print(dice[1])