Note that there are some explanatory texts on larger screens.

plurals
  1. PODivide N cake to M people with minimum wastes
    primarykey
    data
    text
    <p>So here is the question:</p> <p>In a party there are n different-flavored cakes of volume V1, V2, V3 ... Vn each. Need to divide them into K people present in the party such that </p> <ul> <li><p>All members of party get equal volume of cake (say V, which is the solution we are looking for) </p></li> <li><p>Each member should get a cake of single flavour only (you cannot distribute parts of different flavored cakes to a member). </p></li> <li><p>Some volume of cake will be wasted after distribution, we want to minimize the waste; or, equivalently, we are after a maximum distribution policy</p></li> </ul> <p>Given known condition that: if V is an optimal solution, then at least one cake, X, can be divided by V without any volume left, i.e., Vx mod V == 0</p> <p>I am trying to look for a solution with best time complexity (brute force will do it, but I need a quicker way). </p> <p>Any suggestion would be appreciated.</p> <p>Thanks</p> <p>PS: It is not an assignment, it is an Interview question. Here is the pseducode for brute force:</p> <pre><code>int return_Max_volumn(List VolumnList) { maxVolumn = 0; minimaxLeft = Integer.Max_value; for (Volumn v: VolumnList) for i = 1 to K people targeVolumn = v/i; NumberofpeoplecanGetcake = v1/targetVolumn + v2/targetVolumn + ... + vn/targetVolumn if (numberofPeopleCanGetcake &gt;= k) remainVolumn = (v1 mod targetVolumn) + (v2 mod targetVolumn) + (v3 mod targetVolumn + ... + (vn mod targetVolumn) if (remainVolumn &lt; minimaxLeft) update maxVolumn to be targetVolumn; update minimaxLeft to be remainVolumn return maxVolumn } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload