Test instructions
Given the n logarithm, which indicates that there are 2 * n numbers, only 2 have an odd number of times, the memory limit is 1MB, and now you need to know what these two numbers are.
Exercises
First of all, this problem only two numbers appear odd number of times, then the rest of the number appears even several times, it is easy to think of the "^", the nature of satisfaction is the same number of effects will be offset.
So in the sense of the binary, for the I bit, the record of the number I is 1 of all the numbers of the XOR, then for this array can only appear two values, 0,ans0,ans1,ans0^ans1
And then casually find Ans0, and then with all the number of XOR, different or a bit will know ans1 ~
Code:
#include <cstdio> #include <vector> #include <iostream> #include <algorithm>using namespace std ; #define LL Long Longll s[31], X, Xor, Ans[2];int n;void Add (ll x) {for (int i = 1LL; I >= 0;---I) if ((<< i) & x) s[i] ^= x;} int main () {scanf ("%d", &n), for (int i = 1; I <= 2 * n; ++i) {scanf ("%i64d", &x); Xor ^= X;add (x);} for (int i = +; I >= 0;--i) if (s[i]! = Xor && s[i]) {ans[0] = s[i];break;} Ans[1] = Xor ^ ans[0];if (ans[0] > Ans[1]) swap (ans[0], ans[1]), cout << ans[0] << "" << Ans[1];retur n 0;}
Summarize:
Discover the nature of the topic, and then what is missing to maintain what Qaq
Odd number of times?