Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- JS
- Python
- ํ๋ก์ ํธ
- ๋ชจ๊ฐ์ฝ
- error
- ์ฝ๋ฉ
- node.js
- ๋ฐฑ์ค
- ์๊ณ ๋ฆฌ์ฆ
- ๋๋ฆผ์ฝ๋ฉ
- mongodb
- ๋ ธ๋ง๋์ฝ๋
- ๊ทธ๋ฆฌ๋
- ์ฝ๋ฉํ ์คํธ
- Til
- HTML
- ํ์ด์ฌ
- fe
- react
- ํ๋ก ํธ์๋
- ๊ตญ๋น์ง์
- javascript
- ํฌ๋กค๋ง
- KDT
- heapq
- ํ๋ก๊ทธ๋๋จธ์ค
- CSS
- ์ฝ๋ฉ์ ํ
- ํ ์ดํ๋ก์ ํธ
- ๊ฐ๋ฐ
Archives
- Today
- Total
๐ฑ → ๐ณ
Algorithm) Greedy ๋ณธ๋ฌธ
728x90
์์ 1) 1์ด ๋ ๋ ๊น์ง
while True:
# (N==K๋ก ๋๋์ด๋จ์ด์ง๋ ์)๊ฐ ๋ ๋๊น์ง 1์ฉ ๋นผ๊ธฐ
target = (n//k)*k
count += (n-target)
n = target
if n<k:
break
# K๋ก ๋๋๊ธฐ
count += 1
n//=k
# ๋ง์ง๋ง์ผ๋ก ๋จ์ ์์ ๋ํ์ฌ 1์ฉ ๋นผ๊ธฐ
count += (n-1)
print(count)
728x90
'Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Algorithm) Binary Search(์ด์งํ์) (0) | 2022.10.25 |
---|---|
Algorithm) DFS/BFS (0) | 2022.10.25 |
Algorithm) ์๊ณ ๋ฆฌ์ฆ ์ฑ๋ฅ (0) | 2022.10.25 |
[๋ฐฑ์ค] 18870๋ฒ: ์ขํ ์์ถ python (0) | 2022.10.10 |
[๋ฐฑ์ค] 2108๋ฒ: ํต๊ณํ python (0) | 2022.10.02 |