原文:https://code.google.com/codejam/contest/32004/dashboard#s=p0
A magician does the following magic trick. He puts W white balls and B black balls in his hat and asks someone from the audience, say Bob, to remove pairs of balls in whatever order Bob would desire. After removing a pair of balls, Bob is asked to place a white ball back into the hat if they are the same color. Otherwise he is asked to place a black ball into the hat.
When Bob is left with only one ball in the hat, he asks the magician what color the last ball is. Needless to say, the magician can't see the order by which Bob does the replacements.
The problem is that the magician, like most magicians, is old and sometimes forgets how to do the trick. Being the kind person you are, you are going to help the magician.
这里的黑球和白球就相当于1和0,两个进行异或操作,由于异或操作跟顺序无关,所以直接进行异或运算就可以。更进一步的话,异或操作只和1的个数有关,所以只要计算黑球的个数就可以了。