One thing to realize here is, if XOR of a set of numbers is 0, then splitting the set into two sets (irrespective of how you split) and taking XOR of individual sets gives the same value. With this in mind, you don't have to worry much about how to split. If the XOR of all values is not 0, then there is no way one can split it into 2 sets and keep the young boy not crying.
We also want to maximize the value for the elder brother. So just tak eout the least valued candy from the bag and give it to young boy when XOR of all values is 0, Otherwise say NO. --Srikanth On May 7, 11:41 pm, anilsoni85 <[email protected]> wrote: > While solving the CandySplitting problem yesterday i was thinking the > problem can be solve in folllowing steps > > 1. Read the candies value and put them in an array of int. > 2. Create combination of different way sean can split the candies. > Like for 2nd sample example possible combination could be > Sean Patrick Sean Sum of his own Candies Patrick's > XOR of Sean & Patrick candies > 3 5,6 > 3 3 3 > 5 3,6 > 5 5 5 > 6 3,5 > 6 6 6 > 3,5 6 > 8 6 6 > 3,6 5 > 9 5 5 > 5,6 3 > 11 3 3 > > Sean maximum Sum of candies where Patrick & Sean candies XOR equal is > 11 so the solution is 11 > > But in solutions i did not found anyone's solution using this > approch...and now i am having doubt n how the problem can be solved > without combinations. -- You received this message because you are subscribed to the Google Groups "google-codejam" 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/google-code?hl=en.
