Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. You have N boxes in your room which you want to carry to a different place. There are too many to carry in one trip, so you want to split them into several piles using the following algorithm: if the current pile has at most M boxes, you can carry it as is, otherwise you split it into P parts as equally as possible (i.e. so that the sizes of the parts differ at most by 1) and apply the same algorithm to each of the parts. If you're trying to split less than P boxes into P piles, discard resulting zero-sized piles (see example 2).
  2.  
  3.  
  4.  
  5. Calculate the number of piles you'll get in the end.
  6.  
  7.  
  8.  
  9. The only line of input contains three space-separated integers: N, M and P. 1 <= N <= 100, 1 <= M <= 5, 2 <= P <= 5.
  10.  
  11.  
  12.  
  13. Example 1
  14.  
  15.  
  16.  
  17. input
  18.  
  19.  
  20.  
  21. 11 2 2
  22.  
  23.  
  24.  
  25. output
  26.  
  27.  
  28.  
  29. 7
  30.  
  31.  
  32.  
  33. The sequence of pile splits you do is:
  34.  
  35.  
  36.  
  37. 11 -> 6 + 5
  38.  
  39. 6 -> 3 + 3
  40.  
  41. 5 -> 3 + 2
  42.  
  43. 3 -> 2 + 1 (applied to three piles of 3 boxes each)
  44.  
  45.  
  46.  
  47. You end up with 4 piles of 2 boxes and 3 piles of 1 boxes, a total of 7 piles.
  48.  
  49.  
  50.  
  51. Example 2
  52.  
  53.  
  54.  
  55. input
  56.  
  57.  
  58.  
  59. 3 2 5
  60.  
  61.  
  62.  
  63. output
  64.  
  65.  
  66.  
  67. 3
  68.  
  69.  
  70.  
  71. You have to split a pile of 3 boxes into 5 parts, so you get 3 piles of 1 box and 2 empty piles which you discard.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement