2019HDU多校训练第七场J-Just Repeat
J: Just Repeat
时间限制: 2 Sec 内存限制: 128 MB题目描述
When Cuber QQ was chatting happily in a QQ group one day, he accidentally noticed that there was a counterfeit of him, who stole his avatar and mimicked his tone, and more excessively, had a nickname "Quber CC", which was sarcastic to him. So Cuber QQ decided to play a little game with this Quber CC, and their bet was, whoever lost the game would have to do something really humiliating in front of everyone in the QQ group.
The game is like this. It's a traditional card game. Cuber QQ will play first. Cuber QQ, and his opponent (Quber CC of course), will each possess a hand of cards. There is no number (or rank if you prefer) on the card, but only color (or suit if you prefer). The players play cards alternatively, each player can only play one card in each turn. An additional rule is that, a player must not play a card with the same color as any card which has been played by his/her opponent, but coincidence with a card played by himself/herself is acceptable.
The player who can't play any card loses. This might due to the fact that he/she has cards but he cannot play any due to the game rules, or he doesn't have any cards any more. As a game played between civilized people, the game will be played in a completely transparent manner, where Cuber QQ and Quber CC know exactly what's left in their opponent's hand.
It's now a game attracting thousands of eyes, and you decided to invent a predictor whose job is to predict "who will win if both players play smart" to excite the audience.
The game is like this. It's a traditional card game. Cuber QQ will play first. Cuber QQ, and his opponent (Quber CC of course), will each possess a hand of cards. There is no number (or rank if you prefer) on the card, but only color (or suit if you prefer). The players play cards alternatively, each player can only play one card in each turn. An additional rule is that, a player must not play a card with the same color as any card which has been played by his/her opponent, but coincidence with a card played by himself/herself is acceptable.
The player who can't play any card loses. This might due to the fact that he/she has cards but he cannot play any due to the game rules, or he doesn't have any cards any more. As a game played between civilized people, the game will be played in a completely transparent manner, where Cuber QQ and Quber CC know exactly what's left in their opponent's hand.
It's now a game attracting thousands of eyes, and you decided to invent a predictor whose job is to predict "who will win if both players play smart" to excite the audience.
输入
The first line of the input is a positive integer t, denoting the number of test cases.
Then follows t test cases, each test case starts with space-separated integers n, m, p (1≤n,m≤105, p∈{1,2}). Generally speaking, this should be followed by two lines of integers a1,a2,…,an and b1,b2,…,bm, denoting the colors of Cuber QQ's hand and Quber CC's hand, respectively. Unfortunately, as it turns out, the input will be the bottleneck in that case. So we introduce p to deal with this problem.
For p=1, there follows two lines, where the first line is a1,a2,…,an and the second line is b1,b2,…,bm, all space separated and 0≤ai,bi<109.
For p=2, there follows two lines, which are k1,k2,mod (0≤k1,k2<264, 1≤mod≤109) to generate {ai} and {bi}, respectively.
Here are some instructions on how to generate {ai}, {bi} with k1,k2,mod, which you've probably seen before, somehow:
unsigned long long k1, k2;
unsigned long long rng() {
unsigned long long k3 = k1, k4 = k2;
k1 = k4;
k3 ^= k3 << 23;
k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
return k2 + k4;
}
// generate
read(k1, k2, mod);
for (int i = 0; i < n; ++i)
a[i] = rng() % mod;
read(k1, k2, mod);
for (int i = 0; i < m; ++i)
b[i] = rng() % mod;
Also, the sum of n+m for p=1 does not exceed 5⋅105; the sum of n+m from all test cases does not exceed 107.
Then follows t test cases, each test case starts with space-separated integers n, m, p (1≤n,m≤105, p∈{1,2}). Generally speaking, this should be followed by two lines of integers a1,a2,…,an and b1,b2,…,bm, denoting the colors of Cuber QQ's hand and Quber CC's hand, respectively. Unfortunately, as it turns out, the input will be the bottleneck in that case. So we introduce p to deal with this problem.
For p=1, there follows two lines, where the first line is a1,a2,…,an and the second line is b1,b2,…,bm, all space separated and 0≤ai,bi<109.
For p=2, there follows two lines, which are k1,k2,mod (0≤k1,k2<264, 1≤mod≤109) to generate {ai} and {bi}, respectively.
Here are some instructions on how to generate {ai}, {bi} with k1,k2,mod, which you've probably seen before, somehow:
unsigned long long k1, k2;
unsigned long long rng() {
unsigned long long k3 = k1, k4 = k2;
k1 = k4;
k3 ^= k3 << 23;
k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
return k2 + k4;
}
// generate
read(k1, k2, mod);
for (int i = 0; i < n; ++i)
a[i] = rng() % mod;
read(k1, k2, mod);
for (int i = 0; i < m; ++i)
b[i] = rng() % mod;
Also, the sum of n+m for p=1 does not exceed 5⋅105; the sum of n+m from all test cases does not exceed 107.
输出
For each test case, predict the winner: "Cuber QQ" or "Quber CC".
样例输入
2
6 7 1
1 1 4 5 1 4
1 9 1 9 8 1 0
10 20 2
1 2 10
1 2 10
样例输出
Cuber QQ
Quber CC
思路
用pair<int ,int> 记录每种牌的颜色和数量,然后将自己有的牌而对方没有的牌分给自己,最后也是用pair<int ,int> sum[] 记录下双方都的牌,first和second分别记录的是qq,cc有的这种牌的数量,颜色不需要记录,对答案无影响。然后将sum[]按first+secon从大到小排序,依次将所有牌分配给qq和cc,( for(i=0->len-1) 若(i&1)==0,qq+=sum[i].first,否则cc+sum[i].second)。
AC代码
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef pair<int,int> pii; 5 typedef unsigned long long ull; 6 const int maxn=1e6+7; 7 template <class T> 8 inline void read(T &x) 9 { 10 T ans=0,f=1; 11 char ch=getchar(); 12 while((ch<'0'||ch>'9')) 13 { 14 if(ch=='-')f=-1; 15 ch=getchar(); 16 } 17 while(ch>='0'&&ch<='9') 18 { 19 ans=ans*10+ch-'0'; 20 ch=getchar(); 21 } 22 x=ans*f; 23 } 24 ull k1,k2,mod,cc,qq; 25 ull a[maxn],b[maxn]; 26 pii pa[maxn],pb[maxn],sum[maxn]; 27 ull rng() 28 { 29 ull k3=k1,k4=k2; 30 k1=k4; 31 k3^=k3<<23; 32 k2=k3^k4^(k3>>17)^(k4>>26); 33 return k2+k4; 34 } 35 ull slt(pii p[],ull arr[],ull len) 36 { 37 ull k=0; 38 arr[len]=-1; 39 for(ull i=0,j=0; i<len; i=j) 40 { 41 for(; j<len&&arr[i]==arr[j]; ++j); 42 p[k++]=pii(arr[i],j-i); 43 } 44 return k; 45 } 46 bool cmp(pii a,pii b) 47 { 48 return a.first+a.second>b.first+b.second; 49 } 50 int main() 51 { 52 ll t; 53 read(t); 54 while(t--) 55 { 56 cc=0; 57 qq=0; 58 ull n,m,p; 59 read(n); 60 read(m); 61 read(p); 62 if(p==2) 63 { 64 read(k1); 65 read(k2); 66 read(mod); 67 for (ull i=0; i<n; ++i) 68 a[i]=rng()%mod; 69 read(k1); 70 read(k2); 71 read(mod); 72 for (ull i=0; i<m; ++i) 73 b[i]=rng()%mod; 74 } 75 else if(p==1) 76 { 77 for(ull i=0; i<n; ++i) 78 { 79 read(a[i]); 80 } 81 for(ull i=0; i<m; ++i) 82 { 83 read(b[i]); 84 } 85 } 86 sort(a,a+n); 87 sort(b,b+m); 88 ull lena=slt(pa,a,n); 89 ull lenb=slt(pb,b,m); 90 ull k=0; 91 for(ull i=0,j=0; i<lena||j<lenb;) 92 { 93 if(i<lena&&j<lenb&&pa[i].first==pb[j].first) 94 { 95 sum[k++]=pii(pa[i++].second,pb[j++].second); 96 } 97 else if(i==lena||(j<lenb&&pb[j].first<pa[i].first)) 98 { 99 cc+=pb[j++].second; 100 } 101 else 102 { 103 qq+=pa[i++].second; 104 } 105 } 106 sort(sum,sum+k,cmp); 107 for(ull i=0; i<k; ++i) 108 { 109 if(i&1)cc+=sum[i].second; 110 else qq+=sum[i].first; 111 } 112 if(qq>cc)puts("Cuber QQ"); 113 else puts("Quber CC"); 114 } 115 return 0; 116 } 117 /* 118 2 119 6 7 1 120 1 1 4 5 1 4 121 1 9 1 9 8 1 0 122 10 20 2 123 1 2 10 124 1 2 10 125 */