CQRXLB

Accepted : 19   Submit : 40
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 \\((1\\le n\\le 100, 1\\le x\\le 9)\\). The second line contains n positive integers indicates the amount of stones in each pile.

All inputs are no more than \\(10^9\\).

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+BASH博弈。

别问为什么,赛场上我肯定推不出来的,只能靠猜想+证明。

猜想:将每个石子堆$n_{k}$ 变为二进制数,对所有的$n_{k}$,把各位分别加起来,并%(x+1),然后把各位求和sum。若sum==0则后手赢,否则先手赢。

公平组合博弈的平衡和非平衡态满足的条件:
• 1、平衡态时,不可能转移到另外的平衡态。
• 2、非平衡态时,一定可以转移到平衡态的状态。
• 3、最终的状态是平衡态。且有限步数内会结束。

显然上面的sum==0对应平衡态,sum!=0对应非平衡态,读者可以自己证明下。

 #include<cstdio>
#include<iostream>
#include<cstring>
#define clr(x) memset(x,0,sizeof(x))
using namespace std;
int a[];
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n,m,k,t,l,maxt,sum;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
clr(a);
maxt=;
for(int i=;i<=n;i++)
{
scanf("%d",&l);
t=;
while(l)
{
t++;
a[t]=(a[t]+(l%))%(m+);
l/=;
} maxt=max(maxt,t);
}
sum=;
for(int i=;i<=maxt;i++)
{
sum+=a[i];
}
if(sum)
printf("CQR\n");
else
printf("XLB\n");
}
return ;
}

博弈论

xtuoj 1235 CQRXLB(博弈论)的更多相关文章

  1. IT人生知识分享:博弈论的理性思维

    背景: 昨天看了<最强大脑>,由于节目比较有争议性,不知为什么,作为一名感性的人,就想试一下如果自己理性分析会是怎样的呢? 过程是这样的: 中国队(3人)VS英国队(4人). 1:李建东( ...

  2. [poj2348]Euclid's Game(博弈论+gcd)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9033   Accepted: 3695 Des ...

  3. 博弈论揭示了深度学习的未来(译自:Game Theory Reveals the Future of Deep Learning)

    Game Theory Reveals the Future of Deep Learning Carlos E. Perez Deep Learning Patterns, Methodology ...

  4. TYVJ博弈论

    一些比较水的博弈论...(为什么都没有用到那什么SG呢....) TYVJ 1140  飘飘乎居士拯救MM 题解: 歌德巴赫猜想 #include <cmath> #include < ...

  5. Codeforces 549C. The Game Of Parity[博弈论]

    C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. 【POJ】2234 Matches Game(博弈论)

    http://poj.org/problem?id=2234 博弈论真是博大精深orz 首先我们仔细分析很容易分析出来,当只有一堆的时候,先手必胜:两堆并且相同的时候,先手必败,反之必胜. 根据博弈论 ...

  7. 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏

    文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...

  8. poj 3710 Christmas Game 博弈论

    思路:首先用Tarjan算法找出树中的环,环为奇数变为边,为偶数变为点. 之后用博弈论的知识:某点的SG值等于子节点+1后的异或和. 代码如下: #include<iostream> #i ...

  9. hdoj 1404 Digital Deletions(博弈论)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1404 一看就是博弈论的题目,但并没有什么思路,看了题解,才明白 就是求六位数的SG函数,暴力一遍,打表 ...

随机推荐

  1. 【51NOD-0】1130 N的阶乘的长度 V2(斯特林近似)

    [算法]数学 [题解]斯特林公式: #include<cstdio> #include<algorithm> #include<cmath> using names ...

  2. 【51NOD-0】1006 最长公共子序列Lcs

    [算法]经典DP [题解]经典lcs,输出路径可以记录上一个有效节点就是有点麻烦. 因为开始时写法不太明确,打印结果时初始循环地方搞错了,后来修正写法时忘了改过来,调了好久. #include< ...

  3. 【洛谷 P2513】 [HAOI2009]逆序对数列(DP)

    题目链接 这种求方案数的题一般都是\(dp\)吧. 注意到范围里\(k\)和\(n\)的范围一样大,\(k\)是完全可以更大的,到\(n\)的平方级别,所以这暗示了我们要把\(k\)写到状态里. \( ...

  4. 并查集入门--畅通工程(HDU1232)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 畅通工程 Time Limit: 4000/2000 MS (Java/Others)    M ...

  5. new操作符(翻译自mozilla.org)

    翻译自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new new操作符可以实例化一个用户自 ...

  6. ubuntu下定时弹窗记录工作日志

    背景 记录工作日志,是一个很好的习惯,但不容易坚持,本来打算每天记录,但经常拖延,拖着拖着,有一些事情就忘记了. 等到写周报或月报的时候,才会开始翻邮件,聊天记录,各个仓库的提交log等,回忆都干了些 ...

  7. [Linux]Linux printf 输出重定向【转】

    转自:http://www.cnblogs.com/aaronLinux/p/6765145.html?utm_source=itdadao&utm_medium=referral 方法一 # ...

  8. Jmeter===Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍(转)

    Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍 要求: 今天要测试上千条数据,且每条数据要求执行多次,(模拟多用户多次抽奖) 1.用户id有175个,且没有任何排序规 ...

  9. memcached和redis区别

    Memcached:是高性能分布式内存缓存服务器,本质是一个内存 key-value 数据库,但不支持数据持久化,服务器关闭后,数据全丢失.只支持 key-value 结构. Redis:将大部分数据 ...

  10. Spring + MyBatis 多数据源实现

    近期,在项目中需要做分库,但是因为某些原因,没有采用开源的分库插件,而是采用了同事之前弄得多数据源形式实现的分库.对于多数据源,本人在实际项目也中遇到的不多,之前的项目大多是服务化,以RPC的形式获得 ...