[Google 2017 Apac] Robot Rock Band
2016-07-05 16:39
441 查看
Problem
You're the manager of Xorbitant, the world's first robot rock band. There will be four positions in the band, and there are N robots auditioning for each position. (No robot is auditioningfor more than one position.) Every robot has a number, and multiple robots might have the same number, just as two people can have the same name.
You know from market research that your robot audiences won't care how well the robot band members make music, how handsome they are, or what scandalous things the tabloids say about them. Instead, the
audience will be checking to see whether the four members' numbers, when bitwise XORed together, equal a certain trendy number K.
How many different sets of four robots (one for each position) is it possible to choose so that the band will have this property? More specifically, 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.)
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each case begins with one line with two space-separated integers, N and K,as described above. Then, four more lines follow. Each has N space-separated integers and represents the ID numbers of the robots auditioning for a certain position in the band.
Output
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the number of different bands that meet the conditions.Limits
1 ≤ T ≤ 10.0 ≤ K ≤ 109.
0 ≤ all robot numbers ≤ 109.
Small dataset
1 ≤ N ≤ 50.Large dataset
1 ≤ N ≤ 1000.Sample
Input | Output |
2 2 3 0 0 2 0 0 0 0 1 2 0 1 10 1 10 1 10 1 10 | Case #1: 4 Case #2: 8 |
of the two 0 robots can be chosen, so there are 2 * 2 = 4 possible bands that meet the criteria. Note that even though all of these bands are of the form (0, 2, 0, 1), they are considered different because the selections from the lists were different.
题解:哈希,查找,异或位运算
#include <bits/stdc++.h>
using namespace std;
int num[4][1001];
int main() {
freopen("B-large-practice.in", "r", stdin);
freopen("B-large.out", "w", stdout);
int t;
scanf("%d",&t);
int n,k;
string s;
for(int cnt=1;cnt<=t;cnt++) {
scanf("%d%d",&n,&k);
for(int i=0;i<4;i++) {
for(int j=0;j<n;j++) {
scanf("%d",&num[i][j]);
}
}
unordered_map<int,long long> map1,map2;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
map1[num[0][i]^num[1][j]]++;
map2[num[2][i]^num[3][j]]++;
}
}
long long ans=0;
unordered_map<int,long long>::iterator it;
for(it=map1.begin();it!=map1.end();it++) {
int tmp=k^(it->first);
ans+=it->second*(map2[tmp]);
}
printf("Case #%d: %lld\n",cnt,ans);
}
return 0;
}
相关文章推荐
- android Google Map获取地理位置信息的方法
- 谷歌 Project Zero 团队宣布新政策,漏洞披露前将有完整的 90 天缓冲期
- Android使用Google Map浅谈
- 专家解读:开源软件项目是否会被限制出口?
- 专家解读:开源软件项目是否会被限制出口?
- 书评:《算法之美( Algorithms to Live By )》
- Google排名算法改变 不在以外部链为主
- 动易2006序列号破解算法公布
- Google Adsense 支票托收信息收集 (1-30-2007)
- Google Adsense常用技巧总结
- Google推广的十二点技巧
- google优化圣经做网站必备第1/3页
- Google AdSense英文高价关键词排行列表
- C#递归算法之分而治之策略
- Ruby实现的矩阵连乘算法
- Google 统计图表(Flash)小插件
- 2月份停止Google Adsense下线推介 将在中国地区停止投放
- C#插入法排序算法实例分析
- C#算法之大牛生小牛的问题高效解决方法