Skip to content

Commit

Permalink
Merge pull request #71 from AlgoLeadMe/20-alstjr7437
Browse files Browse the repository at this point in the history
20-alstjr7437
  • Loading branch information
alstjr7437 authored Apr 10, 2024
2 parents 880f71d + 717d167 commit 2aba355
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions alstjr7437/BFS/숨바꼭질.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from collections import deque

n, k = map(int, input().split())

result = [0] * 100001
result[n] = 1

queue = deque()
queue.append(n)

while queue:
now = queue.popleft()
if now == k:
break
# -1 로직
if now - 1 >= 0 and result[now-1] == 0 :
queue.append(now-1)
result[now-1] = result[now] + 1
# +1 로직
if now + 1 < len(result) and result[now+1] == 0:
queue.append(now+1)
result[now+1] = result[now] + 1
# *2 로직
if now * 2 < len(result) and result[now * 2] == 0:
queue.append(now*2)
result[now*2] = result[now] + 1

print(result[k] - 1)
3 changes: 2 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
| 16차시 | 2024.03.13 | 정렬 | <a href="https://www.acmicpc.net/problem/2170">선 긋기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/57 |
| 17차시 | 2024.03.16 | DP | <a href="https://www.acmicpc.net/problem/2228">구간 나누기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/61 |
| 18차시 | 2024.03.23 | 다익스트라 | <a href="https://www.acmicpc.net/problem/1753">최단 경로</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/66 |
| 19차시 | 2024.03.27 | 문자열 | <a href="https://www.acmicpc.net/problem/5525">IOIOI</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/67 |
| 19차시 | 2024.03.27 | 문자열 | <a href="https://www.acmicpc.net/problem/5525">IOIOI</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/67 |
| 20차시 | 2024.04.03 | BFS | <a href="https://www.acmicpc.net/problem/1697">숨바꼭질</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/70 |

0 comments on commit 2aba355

Please sign in to comment.