본문 바로가기

boj

백준 5014 스타트링크

 

from collections import deque

#f=총 층, g=스타트링크의 층, s=내가있는층, u=u층위로, d=d층아래로
f,s,g,u,d=map(int,input().split())

arr=[-1 for _ in range(f+1)]

que=deque([s])
arr[s]=0

if s==g:
    print(0)
    exit()

while que:
    now=que.popleft()
    
    for next in (now+u,now-d):
        if 0<next<=f and arr[next]==-1:
            arr[next]=arr[now]+1
            que.append(next)

            if next==g:
                print(arr[next])
                exit()

print("use the stairs")

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

간단한 dfs문제

처음에 틀렸는데, 내가있는층==가고싶은층일때를 제외했기 때문

설명 x

'boj' 카테고리의 다른 글

백준 15686치킨배달  (0) 2022.05.13
백준 14502 연구소  (0) 2022.05.12
백준 1967 트리의 지름  (0) 2022.05.12
백준 11404플로이드  (0) 2022.05.12
백준 1167 트리의 지름  (0) 2022.05.12