Skip to content

Commit

Permalink
2024-09-13 동전 0
Browse files Browse the repository at this point in the history
  • Loading branch information
suhyun113 committed Sep 13, 2024
1 parent 74486ca commit c3e3e9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion suhyun113/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
| 9μ°¨μ‹œ | 2024.05.28 | λ‹€μ΅μŠ€νŠΈλΌ | [μ΅œμ†ŒλΉ„μš© κ΅¬ν•˜κΈ°](https://www.acmicpc.net/problem/1916) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/33) |
| 10μ°¨μ‹œ | 2024.07.13 | ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ | [ν”Œλ‘œμ΄λ“œ](https://www.acmicpc.net/problem/11404) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/36) |
| 11μ°¨μ‹œ | 2024.07.16 | BFS | [μ—°κ΅¬μ†Œ](https://www.acmicpc.net/problem/14502) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/39) |
| 12μ°¨μ‹œ | 2024.07.24 | 이뢄 탐색 | [λ‚˜λ¬΄ 자λ₯΄κΈ°](https://www.acmicpc.net/problem/2805) | [#42](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/42) |
| 12μ°¨μ‹œ | 2024.07.24 | 이뢄 탐색 | [λ‚˜λ¬΄ 자λ₯΄κΈ°](https://www.acmicpc.net/problem/2805) | [#42](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/42) |
| 16μ°¨μ‹œ | 2024.09.13 | 그리디 | [동전 0](https://www.acmicpc.net/problem/11047) | [#49](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/49) |
19 changes: 19 additions & 0 deletions suhyun113/그리디/16-suhyun113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 11047 : 동전 0

# λ™μ „μ˜ μ’…λ₯˜μ™€ λͺ©ν‘œ κΈˆμ•‘μ„ μž…λ ₯λ°›μ•„ μ΅œμ†Œ 동전 개수λ₯Ό κ³„μ‚°ν•˜λŠ” ν•¨μˆ˜
def min_coins(n, k, coins):
count = 0 # 동전 개수λ₯Ό μ„ΈκΈ° μœ„ν•œ λ³€μˆ˜
for coin in reversed(coins): # λ™μ „μ˜ μ’…λ₯˜λ₯Ό 큰 것뢀터 μž‘μ€ 것 순으둜 탐색
if k == 0: # λͺ©ν‘œ κΈˆμ•‘μ΄ 0이면 더 이상 동전을 μ‚¬μš©ν•  ν•„μš” μ—†μŒ
break
count += k // coin # ν˜„μž¬ λ™μ „μœΌλ‘œ λ§Œλ“€ 수 μžˆλŠ” μ΅œλŒ€ 개수 μΆ”κ°€
k %= coin # 남은 κΈˆμ•‘ μ—…λ°μ΄νŠΈ
return count # μ΅œμ†Œ 동전 개수 λ°˜ν™˜

# μž…λ ₯ λ°›κΈ°
n, k = map(int, input().split()) # λ™μ „μ˜ μ’…λ₯˜(n)와 λͺ©ν‘œ κΈˆμ•‘(k) μž…λ ₯
coins = [int(input()) for _ in range(n)] # λ™μ „μ˜ μ’…λ₯˜ μž…λ ₯

# μ΅œμ†Œ 동전 개수 계산 및 좜λ ₯
result = min_coins(n, k, coins)
print(result)

0 comments on commit c3e3e9e

Please sign in to comment.