【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;
}

 

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