题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655

题意是说两个人都有一些带有颜色的牌,两人轮流出牌,但是不能出对面出过的颜色的牌,最后谁不能出牌谁输。

贪心的想,如果这种牌我有对方也有,那我肯定先出以此来减少对方可出的牌,如果有几种这样的牌,那肯定是先出两方手牌总和最多的那种颜色。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 2e5 + ;
struct node {
ll id, num;
node() {}
node(ll _id, ll _num) { id = _id, num = _num; }
}q[maxn];
int a[maxn], b[maxn], num[maxn], numa[maxn], numb[maxn];
ull k1, k2;
int mod;
ull rng() {
unsigned long long k3 = k1, k4 = k2;
k1 = k4;
k3 ^= k3 << ;
k2 = k3 ^ k4 ^ (k3 >> ) ^ (k4 >> );
return k2 + k4;
}
bool cmp(node a, node b) {
return a.num > b.num;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m, p, len = , cnt = ;
scanf("%d%d%d", &n, &m, &p);
if (p == ) {
for (int i = ; i <= n; i++)
scanf("%d", &a[i]), num[++len] = a[i];
for (int i = ; i <= m; i++)
scanf("%d", &b[i]), num[++len] = b[i];
}
else {
scanf("%llu%llu%d", &k1, &k2, &mod);
for (int i = ; i <= n; i++)
a[i] = (int)(rng() % mod), num[++len] = a[i];
scanf("%llu%llu%d", &k1, &k2, &mod);
for (int i = ; i <= m; i++)
b[i] = (int)(rng() % mod), num[++len] = b[i];
}
sort(num + , num + + len);
len = unique(num + , num + + len) - num - ;
for (int i = ; i <= len; i++)
numa[i] = numb[i] = ;
for (int i = ; i <= n; i++) {
int x = lower_bound(num + , num + + len, a[i]) - num;
numa[x]++;
}
for (int i = ; i <= m; i++) {
int x = lower_bound(num + , num + + len, b[i]) - num;
numb[x]++;
}
for (int i = ; i <= len; i++) {
if (numa[i] && numb[i])
q[++cnt] = node(i, numa[i] + numb[i]);
}
sort(q + , q + + cnt, cmp);
int w = , suma = n, sumb = m;
for (int i = ; i <= cnt; i++) {
if (w & )
suma--, sumb -= numb[q[i].id];
else
sumb--, suma -= numa[q[i].id];
w++;
}
if (w & ) {
if (suma > sumb)
printf("Cuber QQ\n");
else
printf("Quber CC\n"); }
else {
if (sumb > suma)
printf("Quber CC\n");
else
printf("Cuber QQ\n"); }
}
}
05-27 22:36