728x90
https://www.acmicpc.net/problem/1697
from collections import deque
n, k = map(int, input().split())
MAX = 10**5 #1
distance = [0] * (MAX + 1) #2
def bfs():
q = deque()
q.append(n)
while q:
x = q.popleft()
if x == k: #3
print(distance[x])
break
for nx in (x-1, x+1, 2*x): #4
if 0 <= nx <= MAX and distance[nx] == 0: #5
distance[nx] = distance[x] + 1
q.append(nx)
bfs()
728x90
'[Coding Test] > [백준]' 카테고리의 다른 글
[백준] 11724: 연결 요소의 개수 (0) | 2022.07.08 |
---|---|
[백준] 1929 파이썬(python) : 소수 구하기 - (에라토스테네스의 체) (0) | 2022.07.05 |
[백준] 7569: 토마토 (0) | 2022.06.30 |
[백준] 2667: 단지번호붙이기 (0) | 2022.06.29 |
[백준] 2178: 미로 탐색 (0) | 2022.06.27 |