Editorial for COCI '09 Contest 7 #2 Cokolada


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

First, note that the smallest possible size that contains K squares is the smallest power of 2 larger than or equal to K.

A greedy strategy yields the smallest number of breaks required to reduce 2^X to K. First we break the piece in two, yielding two pieces, both smaller than K, with 2^{X-1} squares each. We now take one of them and need K-2^{X-1} squares more of the other one. We break that one in half and repeat the process. Each time we need more than half of the current square, we keep one part. Otherwise, we throw that part away.


Comments

There are no comments at the moment.