Skip to content

Commit

Permalink
Merge pull request #16 from AlgoLeadMe/4-seongwon030
Browse files Browse the repository at this point in the history
4-seongwon030
  • Loading branch information
seongwon030 authored Mar 26, 2024
2 parents 5b0738e + 7245736 commit 3582945
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
11 changes: 6 additions & 5 deletions seongwon030/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :---: | :--------: | :------: | :-----------------------------------------------: | :------------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.11 | ์Šคํƒ | [์‡ ๋ง‰๋Œ€๊ธฐ](https://www.acmicpc.net/problem/10799) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/2) |
| 2์ฐจ์‹œ | 2024.03.16 | BFS | [ํ† ๋งˆํ† ](https://www.acmicpc.net/problem/7576) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/7) |
| 3์ฐจ์‹œ | 2024.03.19 | BFS | [ํ† ๋งˆํ† ](https://www.acmicpc.net/problem/7569) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/9) |
| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :---: | :--------: | :------: | :------------------------------------------------: | :------------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.11 | ์Šคํƒ | [์‡ ๋ง‰๋Œ€๊ธฐ](https://www.acmicpc.net/problem/10799) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/2) |
| 2์ฐจ์‹œ | 2024.03.16 | BFS | [ํ† ๋งˆํ† ](https://www.acmicpc.net/problem/7576) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/7) |
| 3์ฐจ์‹œ | 2024.03.19 | BFS | [ํ† ๋งˆํ† ](https://www.acmicpc.net/problem/7569) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/9) |
| 4์ฐจ์‹œ | 2024.03.25 | BFS | [์ˆจ๋ฐ”๊ผญ์งˆ3](https://www.acmicpc.net/problem/13549) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/9) |

---
28 changes: 28 additions & 0 deletions seongwon030/bfs/์ˆจ๋ฐ”๊ผญ์งˆ3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from collections import deque
import sys

input = sys.stdin.readline

result = 0
MAX = 10**5 # ์›€์ง์ผ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€์ขŒํ‘œ
dist = [-1] * (MAX + 1) # ํ•ด๋‹น ์œ„์น˜์— ๋„์ฐฉํ–ˆ์„ ๋•Œ ์‹œ๊ฐ„
n, k = map(int,input().split())

q = deque()
q.append(n)
dist[n] = 0 # ์‹œ์ž‘์œ„์น˜๋ฅผ ์ฒดํฌํ•˜๊ธฐ ์œ„ํ•ด 0์œผ๋กœ ์„ค์ •
while q:
x = q.popleft()
if x==k: # x๋ณ€์ˆ˜์ธ ์ˆ˜๋นˆ์˜ ์œ„์น˜๊ฐ€ ๋™์ƒ์ด ์žˆ๋Š” k์™€ ๊ฐ™์„ ๋•Œ ๋ฉˆ์ถค
result = dist[x]
break
# nx = 4,6,10 (ํ˜„์žฌ ์œ„์น˜ 5์ผ ๋•Œ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉํ–ฅ)
for nx in (x*2, x-1, x+1):
# ๋ฒ”์œ„๋‚ด์— ์žˆ๊ณ  ์•„์ง ๋ฐฉ๋ฌธ์•ˆํ–ˆ๋‹ค๋ฉด
if 0<=nx<=MAX and dist[nx] == -1:
if nx == x*2: # ๊ณฑํ•˜๊ธฐ2๋ฅผ ํ•œ ์ขŒํ‘œ๋ถ€ํ„ฐ ์ฒดํฌ
dist[nx] = dist[x]
else:
dist[nx] = dist[x] + 1
q.append(nx)
print(result)

0 comments on commit 3582945

Please sign in to comment.