2019 Multi-University Training Contest 7 Just Repeat (博弈)

3 篇文章 0 订阅

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1134    Accepted Submission(s): 204


 

Problem Description

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 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.

 

 

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

 

 

Source

2019 Multi-University Training Contest 7

 

 

Recommend

chendu   |   We have carefully selected several similar problems for you:  6656 6655 6654 6653 6652 

 

 

Statistic | Submit | Discuss | Note

题意: 两个人打牌

给出p, 若p = 1, 则输入n个数, m个数;

若 p = 2, 则使用题目所给的rng函数生成数据。

QQ有n张牌, CC有m张牌, 每个人每轮要出一张牌, 规则是不能出对方出过的牌, 但是

可以出自己出过牌,最后轮到谁无牌可出则输掉。思路就是当前出牌者, 选择场上出现总数

最多, 且双方都有的牌。

两种情况:

 1对方这张牌多, 则对方后续不能再出此牌。

2 自己这张牌多, 则对方不能在下一轮出这张牌来减少自己的牌

所以先将公共出现的牌统计, 并从大到小排序, 每轮取场上最大值

最后双方都是不同的牌, 比较牌数即可。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define debug(x) cout << "[" __FUNCTION__ ": " #x " = " << (x) << "]\n"
#define TIME cout << "RuningTime: " << clock() << "ms\n", 0
#else
#define TIME 0
#endif
#define continue(x) { x; continue; }
#define break(x) { x; break; }
const int N = 1e5 + 10;
int a[N];
int b[N];
struct node{
    int tot;
    int u;
    int v;
    bool operator < (const node &oth)const
    {
        return tot > oth.tot;
    }
}d[N];
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;
}
int main(){
#ifdef LOCAL
    freopen("D:/input.txt", "r", stdin);
#endif 
    int t;
    cin >> t;
    while (t--)
    {
        int n, m, p;
        scanf("%d%d%d", &n, &m, &p);
        if (p == 1)
        {
            for (int i = 1; i <= n; i++)
                scanf("%d", &a[i]);
            for (int i = 1; i <= m; i++)
                scanf("%d", &b[i]);
        }
        else
        {
            ll z, x, c;
            scanf("%lld%lld%lld", &z, &x, &c);
            k1 = z, k2 = x;
            for (int i = 1; i <= n; i++)
                a[i] = rng() % c;
            scanf("%lld%lld%lld", &z, &x, &c);
            k1 = z, k2 = x;
            for (int i = 1; i <= m; i++)
                b[i] = rng() % c;
        }
        sort(a + 1, a + 1 + n);
        sort(b + 1, b + 1 + m);
        int i = 1, j = 1;
        int cnt = 1;
        while (i <= n && j <= m) // 统计双方共有牌数
        {
            if (a[i] > b[j])
                j++;
            else
                if (a[i] < b[j])
                    i++;
                else
                    if (a[i] == b[j])
                    {
                        d[cnt].tot = 0;
                        d[cnt].u = d[cnt].v = 0;
                        int num = a[i];
                        while (i <= n && a[i] == num)
                            d[cnt].tot++, d[cnt].u++, i++;
                        while (j <= m && b[j] == num)
                            d[cnt].tot++, d[cnt].v++, j++;
                        cnt++;
                    }
        }
        sort(d + 1, d + cnt); 
        int flag = 0;
        for (int i = 1; i < cnt; i++)  
        {
            if (!flag)
                n--, m -= d[i].v;   // 对方减去该牌
            else
                m--, n -= d[i].u;
            flag ^= 1;
        }
        if (flag) // 接下来CC先手 多则赢
        {
            if (m <= n)
                puts("Cuber QQ");
            else
                puts("Quber CC");
        }
        else // QQ先手
        {
            if (m >= n) 
                puts("Quber CC");
            else
                puts("Cuber QQ");
        }
    }
    return TIME;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值