Hi Marcelo i guess you already answered part of your question "how does one come to this solution?" as you have already mentioned "If the xor of all numbers is zero, you can pick any candy, and the xor to this number is going to be equal to the xor from the rest of them." one can come to this solution by realizing this fact mentioned above .Since maximum sum was desired so you just needed to choose the minimum value from the given set of candies and subtract it from the total sum of candy values (once you check the xor of whole set is 0).
Answering other question I find it hard to figure out alternative uses for XORing integers "other than 1 and 0" in computer science as all the values are stored in binary form and operations are performed on bits. XOR is used in cryptography .This is also used in error detection and correction techniques for data transfer .For example calculating hamming distances, XOR operation plays an important role in Cyclic redundancy check. On May 10, 1:44 am, Marcelo Ramires <[email protected]> wrote: > I understood how to solve this, but *how does one come to this solution ?* > * > If the xor of all numbers is zero, you can pick any candy, and the xor to > this number is going to be equal to the xor from the rest of them.* > > I get this, if I have 9 numbers with XOR 3, XORing it with 3 will get me > zero. > > How has everybody thought of this at the same time ? have I skipped a logics > class ? is this concept so disseminated among coders ? > > I had never XORed nubmers before this code jam, only booleans, and I didn't > know you could. > > As a side questions, can anybody tell me any alternative uses for XORing > integers other than 1 and 0 ? > > Thanks! > > Marcelo Ramires > > > > > > > > On Sun, May 8, 2011 at 1:50 AM, vivek dhiman <[email protected]> wrote: > > Lucky! > > > You are right. > > > if xor of two lists is same. (say xor1 = xo2) > > > So the exor of these two wil be 0 (xor (xor1,xor2) = 0) > > Or in other words lists can be divided if the xor of all the elements is > > zero. > > > :) > > > On Sun, May 8, 2011 at 8:17 AM, keshav agarwal <[email protected]>wrote: > > >> please tell me of my logic was correct or i just got lucky to get it > >> correct > > >> if xor to a list of nos. is zero only then the division is possible > >> in this case patrick can be given the one candy with lowest value while > >> sean keeps the rest > > >> if xor(n nos.)=0 > >> then (nth no.) xor (xor of n-1 nos.)=0 > > >> so patrick gets the nth candy and sean keeps the rest > > >> -- > >> 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. > > > -- > > Regards > > Vivek Dhiman > > > -- > > 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. -- 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.
