I'm looking for a function that can give me the amount of boxes needed for a given amount of items. And if possible, that it gives me an equal, or close to equal, distribution of items in each box. For example, let's say I have 300 items and I know that I can fit 23 in each box. Filling each box with 23 items would require 13 boxes, but leave one item in the last box. A more efficient distribution would be 20 items per box and 15 boxes. Or I could fit 13 boxes with 22 items and 14 in the last one. Either answer is acceptable, but boxes can't be at less than 50% capacity. The amount of boxes can't be more than two over the minimum.
Asked
Active
Viewed 730 times
1
-
What do you mean by "A more efficient distribution"? – louie mcconnell Oct 30 '14 at 00:32
1 Answers
0
lee $f_k(n)$ be the number of boxes needed to store $n$ items, where the capacity of each box is $k$.
$f_k(n)=\lceil \frac{n}{k} \rceil$ where $\lceil \frac{n}{k} \rceil$ is the smallest integer greater than or equal to $\frac{n}{k}$.
Another way to find this is via something very similar to the division algorithm
write $n$ as $mk+r$ with $m,r$ integers and $0< r\leq k$. Then the minimum amount of boxes is $m+1$ and the most "close" distribution is the following:
get $k-r$ boxes with $k-1$ items, get the remaining $m+1-k+r$ boxes with $k$ items.
It is easy to see there are $m+1$ boxes and in total and there are
$(k-r)(k-1)+(m+1-k+r)k=(m+1-k-r+k-r)k-(k-r)=$
$(m+1)k-k+r=mk+r=n$
boxes, so this is the most "equal" and "efficient" arrangement.
Asinomás
- 105,651