Skip to content

Commit

Permalink
Merge pull request #127 from AlgoLeadMe/32-pknujsp
Browse files Browse the repository at this point in the history
32-pknujsp
  • Loading branch information
pknujsp authored Feb 15, 2024
2 parents 429dc67 + bc9939f commit af790fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions pknujsp/BFS/32-숨바꼭질 3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from sys import *
from collections import *

n, k = map(int, stdin.readline().strip().split())

max_idx = 100001

q = deque([(n, 0)])
visited = [False] * max_idx
visited[n] = True

while q:
x, cost = q.popleft()
if x == k:
print(cost)
break

nx = x + x
if nx < max_idx and not visited[nx]:
visited[nx] = True
q.appendleft((nx, cost))

nx = x - 1
if 0 <= nx and not visited[nx]:
visited[nx] = True
q.append((nx, cost + 1))

nx = x + 1
if nx < max_idx and not visited[nx]:
visited[nx] = True
q.append((nx, cost + 1))
3 changes: 2 additions & 1 deletion pknujsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
| 28차시 | 2024.01.16 | 그리디 | [무지의 먹방 라이브](https://school.programmers.co.kr/learn/courses/30/lessons/42891) | [#110](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/110) |
| 29차시 | 2024.01.18 | DFS, UNION-FIND | [순열 사이클](https://www.acmicpc.net/problem/10451) | [#112](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/112) |
| 30차시 | 2024.01.23 | DP | [ABBC](https://www.acmicpc.net/problem/25381) | [#119](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/119) |
| 31차시 | 2024.01.30 | SORT | [멀티버스 Ⅱ](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) |
| 31차시 | 2024.01.30 | SORT | [멀티버스 Ⅱ](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) |
| 32차시 | 2024.02.04 | BFS | [숨바꼭질 3](https://www.acmicpc.net/problem/13549) | [#127](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/127) |

0 comments on commit af790fe

Please sign in to comment.