[파이썬]백준 16928 뱀과사다리게임

Byeonghyeon Kim·2021년 6월 17일
0

알고리즘문제

목록 보기
84/93
post-thumbnail

링크

백준 16928 뱀과사다리게임


아무리 바빠도 알고리즘은 손에 놓으면 안되는것같다 아직..
간만에 푸니까 잘 안풀리더라고
한참 틀리고서야 풀 수 있었다.


정답 코드

from collections import deque
import sys; input = sys.stdin.readline

board = [0] * 101
dis = [101] * 101
l, s = map(int, input().split())
for _ in range(l + s):
    s, e = map(int, input().split())
    board[s] = e

q = deque()
q.append(1)
dis[1] = 0

while q:
    v = q.popleft()
    for i in range(1, 7):
        w = v + i
        if 1 < w < 101 and dis[w] == 101:
            if board[w]:
                w = board[w]
            if dis[w] == 101:
                dis[w] = dis[v] + 1
                q.append(w)

print(dis[-1])

알게된 것👨‍💻

  • 아무리 바빠도 한문제는.. 제발...
profile
자기 주도 개발전 (개발, 발전)

0개의 댓글