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. python初步学习-python数据类型-字典(dict)

    字典 字典类似于你通过联系人名字查找地址和联系人详细情况的地址簿,即,我们把键(名字)和值(详细情况)联系在一起.注意,键必须是唯一的,就像如果有两个人恰巧同名的话,你无法找到正确的信息. 注意,你只 ...

  2. js_读【javascript面向对象编程指南】笔记

    写在前面: 工欲善其事,必先利其器.编程的器,是前人总结的经验,常言道站在巨人的肩膀上开发,往往比自己另辟蹊径容易的多.经验藏于书,故有书中自有颜如玉,书中自有黄金屋,我也一度认为读书要花费很多时间, ...

  3. 项目记录 -- zpool set

    zfs set <property=value> <filesystem|volume|snapshot> root@UA4300D-spa:~/hanhuakai/pro_0 ...

  4. document.onclick在ios上不触发的解决方法与touchstart点击穿透处理

    document.onclick = function (e) { var e = e ? e : window.event; var tar = e.srcElement || e.target; ...

  5. Professional Linux Kernel Architecture 笔记 —— 中断处理(Part 2)【转】

    转自:http://blog.163.com/vic_kk/blog/static/494705242010719483774/ Table of Contents 1 中断 1.1 中断的类型 1. ...

  6. Python-生成器/你不知道的点

    1.什么是生成器 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,如果我们仅仅需要访问前面几个元素, ...

  7. TCP三次握手和四次挥手及用户访问网页流程

    TCP报文格式 TCP通信是通过报文进行的,首先要了解TCP报文的格式. 序号:Seq序号,占32位,用来标识从TCP源端向目的端发送的字节流,发起方发送数据时对此进行标记. 确认序号:Ack序号,占 ...

  8. centos安装VNC的方法

    https://help.aliyun.com/knowledge_detail/6698160.html(阿里云官方文档,但是官方文档有些地方是错的,我更正了下) ----------------- ...

  9. 【机器学习】k-近邻算法应用之手写数字识别

    上篇文章简要介绍了k-近邻算法的算法原理以及一个简单的例子,今天再向大家介绍一个简单的应用,因为使用的原理大体差不多,就没有没有过多的解释. 为了具有说明性,把手写数字的图像转换为txt文件,如下图所 ...

  10. AC日记——「SDOI2017」序列计数 LibreOJ 2002

    「SDOI2017」序列计数 思路: 矩阵快速幂: 代码: #include <bits/stdc++.h> using namespace std; #define mod 201704 ...