The problem with bit arithmetic is very simple, the premise is to first familiar with the bit operation, here to use an XOR operation, that is, ^ this symbol, his operation rule is: the same is 0, the difference is 1. After knowing this, it is easy to think of the same two number of different or after 0, so the following is a key step, but also I think for a long time did not think of a step, is to put all the numbers are different or once again, then the last remaining must be that one, there is a point to note that any number and 0 of the difference or operation is still himself Here's the code:
1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 intMain ()7 {8 intN;9 while(~SCANF ("%d", &N))Ten { One intAns =0;//Initialize Condition A intT; - for(inti =0; I < n; i++) - { thescanf"%d", &t); -Ans ^= t;//XOR or Operation - } -printf"%d\n", ans); + - } + return 0; A}
There is also a code to look at the STL from the Internet as follows:
#include <iostream>#include<cstdio>#include<Set>using namespacestd;intMain () {intN; while(~SCANF ("%d", &N)) {Set<int>S; intT; for(inti =0; I < n; i++) {scanf ("%d", &t); if(S.find (t) = =S.end ()) S.insert (t); Elses.erase (t); } printf ("%d\n", *S.begin ()); } return 0;}
Although the STL code time is relatively long, but this is also a good method, flexible use of STL is very necessary for ACM!
NYOJ528 Finding the ball number (three) bit arithmetic