题意: a[i] ^ x = f[i] ( i = 1...8 ) 和 ( a[1] + a[2] + ... + a[8] ) ^ x = f[9] 现在f为已知 求x
思路:这道题重点就是用异或的思想把十进制数转换成二进制然后一位一位的求,首先我们可以轻松地求得x的最后一位,求得x的最后一位,a[i]的最后一位也就求出来了,那么a[i]最后一位向高位的进位也就求出来了,那么我们就可以把倒数第二位求出来了,依次类推,可以把x的每一位求出来。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#define eps 1e-6
#define LL long long
using namespace std;
//const int maxn = 100 + 5;
//const int INF = 0x3f3f3f3f;
LL m;
LL x1m, x2m, x3m, x4m, x5m, x6m, x7m, x8m, x9m;
LL xm[10];
int main() {
freopen("input.txt", "r", stdin);
int t; cin >> t;
while(t--) {
LL ans = 0;
int jinwei = 0;
for(int i = 0; i < 9; i++) cin >> xm[i];
for(int i = 0; i < 32; i++) {
int cnt = 0;
for(int j = 0; j < 8; j++) {
if(xm[j] & (1<<i)) cnt++;
}
cnt += jinwei;
if((xm[8] & (1<<i))&&cnt%2 == 0 || cnt%2 == 1&&!(xm[8] & (1<<i))) {
ans += (1<<i);
cnt -= jinwei;
cnt = 8 - cnt;
cnt += jinwei;
jinwei = cnt/2;
}
else jinwei = cnt/2;
}
cout << ans << endl;
}
return 0;
}