- All these $k$ sticks have the same length;
- All $k$ sticks are at least as long as all other sticks.
Note that we obtain $n + C$ sticks after performing $C$ cuts. What algorithm would you use such that the number of necessary cuts is minimal? And what is that number? As an example, take $k=2$ and any $ngeq 2$. The following algorithm can be used:
- Order the sticks by descending order of length such that $L_1geq L_2 geq ldots geq L_n$.
- If $L_1geq 2 L_2$ then cut stick #1 to two equal pieces. There are now two sticks of length $L_1 / 2$, which are at least as long as the remaining sticks $2 ldots n$.
- Otherwise ($L_1 < 2 L_2$), cut stick #1 to two unequal pieces of sizes $L_2$ and $L_1-L_2$. There are now two sticks of length $L_2$, which is longer than $L_1-L_2$ and the other sticks $3 ldots n$.
In both cases, a single cut is sufficient. I tried to generalize this to larger $k$, but there seem to be a lot of cases to consider. Can you find an elegant solution?
Asked By : Erel Segal-Halevi
Answered By : Raphael
- $1 leq j leq k$ results in a search space of quadratic size (in $k$),
- $1 leq j leq lceil k/i rceil$ in a linearithmic one (assuming the $L_i$ are sorted by decreasing size), and
- slightly more involved bounds in a linear one.
Using this, we can solve the proposed problem in time $Theta(n + k log k)$ and space $Theta(n + k)$. One further observation is that the sum in $mathrm{Feasible}$ grows in $l$ by $1$ for each candidate $L_i/j$ “passed”, counting duplicates. Using this, we can use rank selection instead of binar search and obtain an algorithm that runs in time and space $Theta(n)$, which is optimal. Find the details in our article Efficient Algorithms for Envy-Free Stick Division With Fewest Cuts (by Reitzig and Wild, 2015).
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/30073