CQRXLB | ||
Accepted : 5 | Submit : 15 | |
Time Limit : 1000 MS | Memory Limit : 65536 KB |
CQRXLBProblem 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. InputThe 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 . OutputFor each test case, puts the name of winner if they both acts perfect. Sample Input2 Sample OutputXLB SourceXTU 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;
}