The number of candies that each student receives varies between [0, m]
start = 0
end = m
Do a binary search to find the largest possible value that can be
distributed.
sol = 1;
while (start <end) {
middle = (start + end) / 2;
ensure that all students can receive the same number of sweets "middle" of a
single box
if possible then {sol = middle; start = middle +1;}
else {end = middle-1;}
}
print sol
Wladimir Araujo Tavares
*Federal University of CearĂ¡
*
On Mon, May 2, 2011 at 12:36 AM, tillegomezz <[email protected]> wrote:
> I have "n" boxes each with "m" candys, I want distributed these candys
> among "k" students
>
> what is the best way for distribute them such that
>
> 1. All students get equal number of candies.
>
> 2. All the candies which a student get must be from a single box only.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.