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
- ํ๋ก์ ํธ
- ๊ตญ๋น์ง์
- heapq
- ๊ทธ๋ฆฌ๋
- error
- mongodb
- ๋๋ฆผ์ฝ๋ฉ
- ์๊ณ ๋ฆฌ์ฆ
- ํ๋ก ํธ์๋
- HTML
- ์ฝ๋ฉ
- ํ๋ก๊ทธ๋๋จธ์ค
- KDT
- ๋ ธ๋ง๋์ฝ๋
- Python
- ์ฝ๋ฉ์ ํ
- CSS
- node.js
- fe
- ๊ฐ๋ฐ
- ์ฝ๋ฉํ ์คํธ
- ํ ์ดํ๋ก์ ํธ
- JS
- ๋ชจ๊ฐ์ฝ
- javascript
- ํฌ๋กค๋ง
- Til
- react
- ๋ฐฑ์ค
- ํ์ด์ฌ
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 |