您的位置:首页 > 其它

Practice Round APAC test 2017--Problem B. Robot Rock Band

2016-10-14 11:02 459 查看
Problem B. Robot Rock Band

题意

given four lists A, B, C, D containing N numbers each, how many ways are there to choose one number a from list A, one number b from list B, and so on, such that a^b^c^d = K? (Here ^ represents the bitwise XOR operation.)

题解

a ^ b ^ c ^ d = k
a ^ b ^ k = c ^ d


#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000 + 5;
int a[maxn], b[maxn], c[maxn], d[maxn];
map<int, long long> mp;
int T, n, k;

int main(){

freopen("B-large-practice.in", "r", stdin);
freopen("B-large-practice.txt", "w", stdout);

cin >> T;
for(int _ = 1; _ <= T; ++_){
cin >> n >> k;
for(int i = 0; i < n; ++i) cin >> a[i];
for(int i = 0; i < n; ++i) cin >> b[i];
for(int i = 0; i < n; ++i) cin >> c[i];
for(int i = 0; i < n; ++i) cin >> d[i];

mp.clear();
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j) mp[c[i] ^ d[j]]++;
}
long long ans = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
int t = a[i] ^ b[j] ^ k;
if(mp.find(t) != mp.end()) ans += mp[t];
}
}
printf("Case #%d: %I64d\n", _, ans);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  apac xor