理解异或和的性质可以发现:如果一个数等于另外一堆数的异或和,那么这个数在异或上这个异或和就结果为0。那么相同的道理,从异或和为0的一堆数中随便拿出一个数,他都是和剩下一堆数异或和相同。得出本题随便输出任何一个数就能AC。怎么回事一天难,一天又简单
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define x first
#define y second
const int mod = 1000000000 + 7;
int ksm(int a, int b, int mod) {
a %= mod;
int res = 1;
while (b) {
if (b & 1) {
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
void solve() {
int n;
cin>>n;
vector<int>a(n+1);
int xo=0;
for(int i=1;i<=n;++i){
cin>>a[i];
xo^=a[i];
}
for(int i=1;i<=n;++i){
if(a[i]^xo==a[i]){
cout<<a[i]<<'\n';
return ;
}
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t = 1;
cin>>t;
while (t--)
solve();
return 0;
}

京公网安备 11010502036488号