Practice Round APAC test 2017——Problem B. Robot Rock Band
来源:互联网 发布:跨越阶层 知乎 编辑:程序博客网 时间:2024/04/30 13:31
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 auditioning for 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
In sample case #1, in order to get a combined bitwise XOR of 3, the robot chosen from the second list must be 2, and the robot chosen from the fourth list must be 1. For the first and third lists, either 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 <iostream>#include <string>#include <vector>#include <set>#include <unordered_map>using namespace std;unordered_map<int, long long int> mp;int main(){ int t,T,N,K; int i,j; cin>>T; for(t=1;t<=T;t++) { cin>>N>>K; int v; vector<int> a,b,c,d; mp.clear(); for(i=0;i<N;i++) { cin>>v; a.push_back(v); } for(i=0;i<N;i++) { cin>>v; b.push_back(v); } for(i=0;i<N;i++) { cin>>v; c.push_back(v); } for(i=0;i<N;i++) { cin>>v; d.push_back(v); } for(i=0;i<N;i++) for(j=0;j<N;j++) mp[a[i]^b[j]]++; long long int ans=0; for(i=0;i<N;i++) for(j=0;j<N;j++) { if(mp.find(c[i]^d[j]^K)!=mp.end()) ans+=mp[c[i]^d[j]^K]; } cout<<"Case #"<<t<<": "<<ans<<endl; } return 0;}
- Practice Round APAC test 2017--Problem B. Robot Rock Band
- Practice Round APAC test 2017——Problem B. Robot Rock Band
- Problem B. Robot Rock Band Google APAC 2017 University Test Practice Round
- [Google 2017 Apac] Robot Rock Band
- Practice Round APAC test 2017——1.Problem A. Lazy Spelling Bee
- Practice Round APAC test 2017——Problem C. Not So Random
- Practice Round APAC test 2017——Problem D. Sums of Sums
- Practice Round APAC test 2017--Problem A. Lazy Spelling Bee
- Round C APAC Test 2017 Problem B. Monster Path
- Round B APAC Test 2017 Problem A. Sherlock and Parentheses
- Round B APAC Test 2017 Problem C. Watson and Intervals
- Round E APAC Test 2017 Problem B. Beautiful Numbers
- Problem B. Rain Google APAC 2017 University Test Round A
- Round C APAC Test 2017 Problem B. Safe Squares (C++)
- Round A APAC Test 2017 Problem B.Rain
- Practice Round APAC test Problem A. Bad Horse 2-sat
- Problem C. Not So Random Google APAC 2017 University Test Practice Round
- Problem A. Lazy Spelling Bee Google APAC 2017 University Test Practice Round
- 最强 Android Studio 使用小技巧和快捷键
- 导入Myeclipse的Java项目,JS文件编译错误: Multiple markers at this line - Missing semicolon - Missing....
- [刷题]算法竞赛入门经典(第2版) 5-13/UVa822 - Queue and A
- canvas
- 浅谈算法和数据结构: 哈希表
- Practice Round APAC test 2017——Problem B. Robot Rock Band
- C# TXT文件导入至数据库
- mongoDB 分组,拆分内嵌子集合
- 缓动动画
- unique和unique_copy函数的应用
- 亿级Web系统搭建-单机到分布式集群
- sql操作报空指针异常
- Mangled name的结构(borland)
- centos7 安装 桌面 desktop