Robot Rock Band
来源:互联网 发布:js a href click 编辑:程序博客网 时间:2024/06/07 13:06
Problem B. Robot Rock Band
6 points
14 points
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.
四道循环一定超时,但可以缩减一下。两个两个来。
两个数组循环统计异或值个数。
另外的两个数组也这样统计,并用map记录。
遍历第一个异或值结果数组,如果与k异或的值可以在map里面找到,则乘法原理结果加到答案里面。
因为异或的结果是可以传递的,所以可以逆向来求。
#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>#include <vector>#include <map>#include <set>const int N = 1000100;typedef long long ll;using namespace std;int mod = 1000000007;ll num[4][N];ll arr1[N], arr2[N];int main(){ freopen("in.txt","r",stdin); freopen("out.txt", "w", stdout); int T, cas = 1; scanf("%d", &T); while (T--) { ll n, k, ans = 0; cin >> n >> k; set<ll>S; map<ll,ll>mp1;mp1.clear(); map<ll,ll>mp2;mp2.clear(); for (int i = 0;i < 4; i++) { for (int j = 0;j < n; j++) cin >> num[i][j]; } int c = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { arr1[c] = num[0][i] ^ num[1][j]; if (mp1.find(arr1[c]) == mp1.end()) mp1[arr1[c]] = 1; else { mp1[arr1[c]] += 1; } c++; } int d = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { arr2[d] = num[2][i] ^ num[3][j]; if (mp2.find(arr2[d]) == mp2.end()) { mp2[arr2[d]] = 1; }else { mp2[arr2[d]] += 1; } d++; } for (int i = 0;i < c; i++) { if (S.find(arr1[i]) != S.end()) continue; S.insert(arr1[i]); ll tmp = arr1[i]^k; if (mp2.find(tmp) != mp2.end()) { ans += mp1[arr1[i]]* mp2[tmp]; } } printf("Case #%d: %lld\n", cas++, ans); } return 0;}
- Robot Rock Band
- [Google 2017 Apac] Robot Rock Band
- 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
- Rock Band下线给应用内付费蒙上阴影
- EA: Rock Band下线的消息咱发错了
- radar band X band
- Robot
- robot
- robot
- Robot
- Robot
- Channel,Band
- Price Band
- Band/Bandwidth
- std::band
- bit-band
- Makefile工程管理
- W7 pydev 安装到ecplise上
- 创建多模块maven工程
- Lazy Spelling Bee
- 链接法hash表
- Robot Rock Band
- Android Service的生命周期
- UISegmentController
- 一个PHP的SQL注入完整过程
- CSS盒子模型(续一)
- Java NIO系列教程(四) Scatter/Gather
- 俚语、口语及常见用法的理解
- Software Testing-How To Design Test Case
- Linux的环境变量.bash_profile .bashrc profile文件