Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5-seongwon030 #23

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions seongwon030/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
| 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) |
| 5μ°¨μ‹œ | 2024.03.30 | BFS | [점프점프](https://www.acmicpc.net/problem/11060) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/9) |

---
23 changes: 23 additions & 0 deletions seongwon030/bfs/점프점프.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from collections import deque

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

cur, jump = 0,0
queue = deque()
queue.append((cur,jump)) # ν˜„μž¬ 인덱슀, 점프 횟수
visited = []

while queue:
cur, jump = queue.popleft()
if cur == len(k)-1: # ν˜„μž¬ μΈλ±μŠ€κ°€ λ§ˆμ§€λ§‰ 칸에 ν•΄λ‹Ήν•˜λ©΄ jump 수 좜λ ₯ ν›„ μ’…λ£Œ
print(jump)
exit()

for i in range(1, k[cur]+1): # kμ•ˆμ— μžˆλŠ” 숫자 μ΄ν•˜λ§ŒνΌ 였λ₯Έμͺ½μœΌλ‘œ 점프 κ°€λŠ₯
next = cur + i # λ‹€μŒ μΈλ±μŠ€λŠ” ν˜„μž¬ 인덱슀 + i
if next not in visited: # λ°©λ¬Έ μ•ˆ ν–ˆμœΌλ©΄ λ‹€μŒ μΈλ±μŠ€μ™€ μ ν”„μˆ˜ 1을 λ”ν•œ 것 큐에 μΆ”κ°€
queue.append((next, jump+1))
visited.append(next) # λ‹€μŒ 인덱슀 λ°©λ¬Έ 처리

print(-1) # 쀑간에 exit μ•ˆν•˜λ©΄ -1 좜λ ₯