[白俊#14499]サイコロを投げる
13816 ワード
1.問題の説明
2.解説
サイコロを投げるのをシミュレートして、濃いサムスンの味を放つ問題.サイコロを投げるときは、各面がどこに移動するかを知ってからコードに変換すればいいです.
3.コード
from sys import stdin
input = stdin.readline
N, M, x, y, K = map(int, input().split())
graph = [list(map(int, input().split())) for _ in range(N)]
# 0: 위, 1: 아래, 2: 앞, 3: 뒤, 4: 왼, 5: 오
dice = [0, 0, 0, 0, 0, 0]
order_list = list(map(int, input().split()))
for order in order_list:
if order == 1: # 동: 위->오, 오->아래, 아래->왼, 왼->위
if y+1 >= M:
continue
else:
up = dice[0]
down = dice[1]
left = dice[4]
right = dice[5]
dice[0] = left
dice[1] = right
dice[4] = down
dice[5] = up
y += 1
elif order == 2: # 서: 오른쪽->위, 위->왼쪽, 왼쪽->아래, 아래->오른쪽
if y-1 < 0:
continue
else:
up = dice[0]
down = dice[1]
left = dice[4]
right = dice[5]
dice[0] = right
dice[1] = left
dice[4] = up
dice[5] = down
y -= 1
elif order == 3: # 북 - 앞->위, 위->뒤, 뒤->아래, 아래->앞
if x-1 < 0:
continue
else:
up = dice[0]
down = dice[1]
front = dice[2]
rear = dice[3]
dice[0] = front
dice[1] = rear
dice[2] = down
dice[3] = up
x -= 1
elif order == 4: # 남 - 위->앞, 앞->아래, 아래->뒤, 뒤->위
if x+1 >= N:
continue
else:
up = dice[0]
down = dice[1]
front = dice[2]
rear = dice[3]
dice[0] = rear
dice[1] = front
dice[2] = up
dice[3] = down
x += 1
if graph[x][y] != 0:
dice[1] = graph[x][y]
graph[x][y] = 0
else:
graph[x][y] = dice[1]
print(dice[0])
Reference
この問題について([白俊#14499]サイコロを投げる), 我々は、より多くの情報をここで見つけました https://velog.io/@tenykim1109/백준-14499-주사위-굴리기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol