코딩 테스트/백준 강의 연습편
BFS) 5014.스타트링크
Carnival7
2022. 6. 11. 21:02
https://www.acmicpc.net/problem/5014
5014번: 스타트링크
첫째 줄에 F, S, G, U, D가 주어진다. (1 ≤ S, G ≤ F ≤ 1000000, 0 ≤ U, D ≤ 1000000) 건물은 1층부터 시작하고, 가장 높은 층은 F층이다.
www.acmicpc.net
from collections import deque
import sys
f,s,g,u,d=map(int,input().split())
q=deque()
q.append((s,0))
check=[False]*(f+1)
check[s]=True
while q:
now,cnt=q.popleft()
if now==g:
print(cnt)
sys.exit(0)
for next in [now+u,now-d]:
if 1<=next<=f and not check[next]:
q.append((next,cnt+1))
check[next]=True
print("use the stairs")