Robot Rock Band

来源:互联网 发布:js a href click 编辑:程序博客网 时间:2024/06/07 13:06

Practice Round APAC test 2017


   Submissions
Lazy Spelling Bee
5pt
Correct
698/1266 users correct (55%)
8pt
Correct
496/685 users correct (72%)
Robot Rock Band
6pt
Correct
480/622 users correct (77%)
14pt
Correct
142/407 users correct (35%)
Not So Random
11pt
Not attempted
204/310 users correct (66%)
20pt
Not attempted
109/158 users correct (69%)
Sums of Sums
8pt
Correct
230/395 users correct (58%)
28pt
Time expired
13/128 users correct (10%)
   Top Scores
Jayam100Seter100KillswitcherEngag...100onepunchman100Sumeet.Varma100gdragon007100libenchao100jpsagarm95100vaibhav227100liubiao2638100
Practice Mode Rank: 135 Score: 41

Problem B. Robot Rock Band

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
6 points
Large input
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, TT 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 
 
22 3 0 02 00 00 12 01 101 101 101 10
Case #1: 4Case #2: 8

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.

 
四个数组,每个数组挑一个数出来,问有多少种情况这四个数的异或值等于k

四道循环一定超时,但可以缩减一下。两个两个来。

两个数组循环统计异或值个数。

另外的两个数组也这样统计,并用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;}





0 0
原创粉丝点击