(Nim博弈)湘潭市赛,CQRXLB

本文探讨了两人石子博弈的策略,通过分析游戏规则,揭示了如何在限制条件下获胜的关键,适合对游戏数学和博弈论感兴趣的读者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CQRXLB

Accepted : 5 Submit : 15
Time Limit : 1000 MS Memory Limit : 65536 KB

CQRXLB

Problem Description:

CQR and XLB are best friends. One night, they are staring each other and feel boring, and XLB says let's play game!

They place n piles of stones and take turns remove arbitrary amount(at least one) of stones in at least one pile at most x piles they chose. The one who can not remove any stone lose out.

CQR is a girl so she always move first. Duoxida wants to know who will win if they are both smart enough.

Input

The first line contains a integer T(no more than 100) indicating the number of test cases.

In each test case, each test case includes two lines. the first line contains two integers n and x . The second line contains n positive integers indicates the amount of stones in each pile.

All inputs are no more than .

Output

For each test case, puts the name of winner if they both acts perfect.

Sample Input

2
3 1
1 3 2
2 2
1000 1000

Sample Output

XLB
CQR


Source

XTU OnlineJudge

题意:有N堆石子,两个人在玩游戏。游戏规则是可以取不超过x堆中任意石子数,至少取一个,不能取者败,问先手还是后手赢。

NIM博弈回顾:
• 1、平衡态时,不可能转移到另外的平衡态。
• 2、⾮非平衡态时,⼀一定可以转移到平衡态的状态。
• 3、最终的状态是平衡态。且有限步数内会结束。


猜想:
• n的石子的二进制位的每⼀一位的和都是(x+1)的倍数时为平衡态。

证明可行性:
• 1、平衡态时,不可能转移到另外的平衡态。
• 2、⾮非平衡态时,一定可以转移到平衡态的状态。
• 3、最终的状态是平衡态。且有限步数内会结束。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int n,x;
int a[33];

void add(int tmp) {
    for(int i = 0; i < 32; i ++) {
        a[i] = (a[i] + tmp % 2) % (x + 1);
        tmp /= 2;
    }
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t --) {
        scanf("%d%d",&n,&x);
        memset(a,0,sizeof(a));
        while(n --) {
            int y;
            scanf("%d",&y);
            add(y);
        }
        int sum = 0;
        for(int i = 0; i < 32; i ++) sum += a[i];
        if(sum) printf("CQR\n");
        else printf("XLB\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值