【2019 Multi-University Training Contest 7 -J HDU - 6655】Just Repeat(贪心)

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. 

Input

The first line of the input is a positive integer tt, denoting the number of test cases. 

Then follows tt test cases, each test case starts with space-separated integers nn, mm, pp (1≤n,m≤1051≤n,m≤105, p∈{1,2}p∈{1,2}). Generally speaking, this should be followed by two lines of integers a1,a2,…,ana1,a2,…,an and b1,b2,…,bmb1,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 pp to deal with this problem. 

For p=1p=1, there follows two lines, where the first line is a1,a2,…,ana1,a2,…,an and the second line is b1,b2,…,bmb1,b2,…,bm, all space separated and 0≤ai,bi<1090≤ai,bi<109. 

For p=2p=2, there follows two lines, which are k1,k2,modk1,k2,mod (0≤k1,k2<2640≤k1,k2<264, 1≤mod≤1091≤mod≤109) to generate {ai}{ai} and {bi}{bi}, respectively. 

Here are some instructions on how to generate {ai}{ai}, {bi}{bi} with k1,k2,modk1,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+mn+m for p=1p=1 does not exceed 5⋅1055⋅105; the sum of n+mn+m from all test cases does not exceed 107107. 

Output

For each test case, predict the winner: "Cuber QQ" or "Quber CC".

Sample Input

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

Sample Output

Cuber QQ
Quber CC

思路:

一个人出过的牌另一个人不能出了,但是自己还可以出,因此先出自己最多的牌或者先出对方最多的牌是比较优的选择,所以将双方都有的牌,统计一下每种颜色的有多少个,由大到小排序,按照顺序依次分给两个人,代表每个人出哪个牌,将这个人拥有这种牌的数量加到自己能出牌的数量中。其他的牌是自己有但对方没有的,加入到自己能出的牌的数量中,最后比较两个人能出牌的数量的多少即可。

样例1解释:公共的牌是1,qq、cc各有3个,然后qq单独有的牌有3张,cc单独有的牌有4张。qq先选,因此从公共的牌对里选数量(两个人各有的牌数加和)最大的,然后将qq含有这个牌的数量加入到自己能出的牌数量中,即3(qq单独含有的)+3(qq含有1号牌的数量)。最后牌分完了,两个人能出的牌是6、4,qq牌数多所以qq胜。

这道题目用map被卡了,换了unordered_map就过了。

ac代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<vector>
#include<tr1/unordered_map>
using namespace std;
typedef long long ll;
const int maxn=100010;
unsigned long long k1, k2,mod;
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;
}
struct node{
    int ta,tb,num;
    friend bool operator<(node a,node b){
        return a.num<b.num;
    }
}c[maxn*2];
tr1::unordered_map<int,int> mp;
int a[maxn],b[maxn];  
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        priority_queue<node> qa,qb,qc;
        int id=1;mp.clear();
        int n,m,p;
        scanf("%d%d%d",&n,&m,&p);
        for(int i=1;i<=m+n+2;i++){
            c[i].ta=c[i].tb=c[i].num=0;
        }
        if(p==1){
            for(int i=0;i<n;i++)scanf("%d",&a[i]);
            for(int i=0;i<m;i++)scanf("%d",&b[i]);
        }
        else{
            // generate
            scanf("%lld%lld%d",&k1,&k2,&mod);
            for (int i = 0; i < n; ++i)
                a[i] = rng() % mod;
            scanf("%lld%lld%d",&k1,&k2,&mod);
            for (int i = 0; i < m; ++i)
                b[i] = rng() % mod;
        } 
        for(int i=0;i<n;i++){
            if(!mp[a[i]]) mp[a[i]]=id++;
            int x=mp[a[i]];
            c[x].ta++;
         }
        for(int i=0;i<m;i++){
            if(!mp[b[i]]) mp[b[i]]=id++;
                int x=mp[b[i]];
                c[x].tb++;
        }
        int na=0,nb=0;
        for(int i=1;i<id;i++){
            c[i].num=c[i].ta+c[i].tb;
            if(c[i].ta==0) nb+=c[i].tb;
            else if(c[i].tb==0) na+=c[i].ta;
            else qc.push(c[i]);
        }
        int x=0;
        while(qc.size()){
            node tmp=qc.top();qc.pop();
            if(x==0){
                na+=tmp.ta;
            }
            else{
                nb+=tmp.tb;
            }
            x^=1;
        }
        if(na>nb) puts("Cuber QQ");
        else puts("Quber CC");
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章