백준 5014번 스타트링크 (Python 3)
2022. 8. 30. 17:40ㆍProblem solving
Baekjoon online judge 5014번 파이썬
링크
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
소스코드
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
def bfs(start):
queue=deque()
queue.append([start,0])
index=[u,-d]
visited=set()
visited.add(start)
while queue:
node,cnt=queue.popleft()
if node==g:
print(cnt)
return
for i in index:
new_node=node+i
if 1<=new_node<=f and new_node not in visited:
visited.add(new_node)
queue.append([new_node,cnt+1])
print('use the stairs')
return
f,s,g,u,d=map(int,input().split())
bfs(s)
'Problem solving' 카테고리의 다른 글
백준 17141번 연구소 2 (Python 3) (0) | 2022.08.30 |
---|---|
백준 17086번 아기 상어 2 (Python 3) (0) | 2022.08.30 |
백준 14395번 4연산 (Python 3) (0) | 2022.08.30 |
백준 1963번 소수 경로 (Python 3) (0) | 2022.08.30 |
ps에 필요한 기본 알고리즘 (python 3) (0) | 2022.08.30 |