Sunday, September 21, 2014

SPOJ 7169. Pizza

The first thing just comes to mind is to add all the number and round up and output the answer, but unfortunately it is not how it works. Suppose we have 3/4 3/4 and 1/2 by doing the way I described above you will calculate 2 pizza's for friends but the answer is 3, because if we by 2 pizzas for 3/4 s then with the remaining 1/4 and 1/4 we can't form one 1/2 . So, here is what I suggest doing for being correct. First of all we need to buy pizzas for all 1/2s (take 2 1/2s and add 1 pizza) until either one 1/2 is left or none. Then we need to buy 1 pizza for 1/2 and 3/4 (until we run out either of 1/4s or 3/4s). If we have 3/4s left then we need to increment the answer by their number. Then we need to add the number of 1/2s *0.5 and the number of 1/4s *0.25 and round up the answer. NOTE Don't forget to add 1 to the total answer (see the problem statement) and output the new line.


       FULL SOURCE CODE

No comments:

Post a Comment