hdu 4149 Magic Potion



题意: 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;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值