Created
July 7, 2020 16:00
-
-
Save inspirit941/6b3db8447fad4ed05c49d1f5fb75af64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from collections import deque | |
# F : 건물의 총 높이 | |
# G : 목적지 | |
# U : 위로 한 번에 이동할 수 있는 폭 | |
# D : 아래로 한 번에 이동할 수 있는 폭 | |
# 현재위치 = S. | |
F, S, G, U, D = map(int, sys.stdin.readline().split()) | |
def bfs(start, end, up, down, F): | |
visited = set() | |
queue = deque() | |
queue.append((0, start)) | |
visited.add(start) | |
while queue: | |
cnt, stairs = queue.popleft() | |
if stairs == end: | |
return cnt | |
if stairs + up <= F and stairs + up not in visited: | |
visited.add(stairs+up) | |
queue.append((cnt+1, stairs+up)) | |
if stairs - down >= 1 and stairs - down not in visited: | |
visited.add(stairs-down) | |
queue.append((cnt+1, stairs-down)) | |
return "use the stairs" | |
print(bfs(S, G, U, D, F)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment