Change the Better World

Greedy Algorithm(1) - Change 본문

Algorithm

Greedy Algorithm(1) - Change

white_cheetah 2021. 9. 11. 15:49

- what is the GREEDY ALGORITHM?

https://en.wikipedia.org/wiki/Greedy_algorithm

 

Greedy algorithm - Wikipedia

From Wikipedia, the free encyclopedia Jump to navigation Jump to search computer science heuristics that makes the locally optimal choice at each stage Greedy algorithms determine the minimum number of coins to give while making change. These are the steps

en.wikipedia.org

Question1. give change to a customer by using greedy algorithm?

₩500, ₩100, ₩50, ₩10

 

money = int(input())

count = 0

 

coin_types  = [500, 100, 50, 10]

for coin in coin_types:

    count += n // coin

    n %= coin

 

return count

 

 

'Algorithm' 카테고리의 다른 글

Implement  (0) 2021.11.14
Greedy Algorithm (2) - law of large numbers  (0) 2021.09.15
Comments