If you must pay an amount in coins, the "intuitive" algorithm is: pay as much as possible with the largest denomination coin, and then go on to pay the rest with the other coins. For example, if there are 25, 5 and 1 cent coins, to pay someone 32 cents, you'd first give him a 25 cents coin, then one 5 cent coin, and finally two 1 cent coins.)
However, this doesn't always end paying with as few coins as possible: if we had 25, 10 and 1 cent coins, paying 32 cents with the "intuitive" algorithm would use 8 coins, while three 10 cent coins and two 1 cent coins would be better.
We can call a set "intuitive", if the "intuitive algorithm" always pays out any amount with as few coins as possible.
The problem: give an algorithm that allows you to decide that {25,5,1} is an "intuitive" set, while {25,10,1} isn't.
The answer for two coins greater than 1 is because 25 is not divisible by 10, but it is divisible by 5. Here's one way to think about it:
For n cents, put down n 1 coins. Then for every 5 1s, put down a 5 coin instead, and for every 5 5s, put down a 25.
This won't work with 1, 10, and 25, because you will need to exchange 2.5 10s for 25, and half a 10 is not allowed.
|
Posted by Gamer
on 2005-03-29 19:39:11 |