xtuoj 1235 CQRXLB(博弈论)
CQRXLB |
||
| Accepted : 19 | Submit : 40 | |
| 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 \\((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\\). OutputFor each test case, puts the name of winner if they both acts perfect. Sample Input2 Sample OutputXLB SourceXTU 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(博弈论)的更多相关文章
- IT人生知识分享:博弈论的理性思维
背景: 昨天看了<最强大脑>,由于节目比较有争议性,不知为什么,作为一名感性的人,就想试一下如果自己理性分析会是怎样的呢? 过程是这样的: 中国队(3人)VS英国队(4人). 1:李建东( ...
- [poj2348]Euclid's Game(博弈论+gcd)
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9033 Accepted: 3695 Des ...
- 博弈论揭示了深度学习的未来(译自:Game Theory Reveals the Future of Deep Learning)
Game Theory Reveals the Future of Deep Learning Carlos E. Perez Deep Learning Patterns, Methodology ...
- TYVJ博弈论
一些比较水的博弈论...(为什么都没有用到那什么SG呢....) TYVJ 1140 飘飘乎居士拯救MM 题解: 歌德巴赫猜想 #include <cmath> #include < ...
- 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 ...
- 【POJ】2234 Matches Game(博弈论)
http://poj.org/problem?id=2234 博弈论真是博大精深orz 首先我们仔细分析很容易分析出来,当只有一堆的时候,先手必胜:两堆并且相同的时候,先手必败,反之必胜. 根据博弈论 ...
- 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏
文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...
- poj 3710 Christmas Game 博弈论
思路:首先用Tarjan算法找出树中的环,环为奇数变为边,为偶数变为点. 之后用博弈论的知识:某点的SG值等于子节点+1后的异或和. 代码如下: #include<iostream> #i ...
- hdoj 1404 Digital Deletions(博弈论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1404 一看就是博弈论的题目,但并没有什么思路,看了题解,才明白 就是求六位数的SG函数,暴力一遍,打表 ...
随机推荐
- LTC 钱包部署
基础环境 系统: CentOS 7.x nodejs: v4.6.0 zeromq: 4.x 安装nodejs + zeromq 基础依赖 yum install -y gcc make gcc-c+ ...
- cocos2dx 某缩放的页面 CCTableView最后一个标签无法点中
有一个二级界面,在ipad4下面放大到1.6倍,直接对最外层的CCLayer缩放的,里面包含有CCTableView.结果运行的时候无法选中到最后一个标签,无论总的标签是2个还是更多,单步调试,发现到 ...
- DotNETCore 学习笔记 WebApi
API Description Request body Response body GET /api/todo Get all to-do items None Array of to-do ite ...
- elementui table 多选 获取id
//多选相关方法 toggleSelection(rows) { if (rows) { rows.forEach(row => { this.$refs.multipleTable.toggl ...
- Python3 嵌套函数
嵌套函数: 函数体内用def定义函数 注意:函数体中调用其他函数不算嵌套函数,只能是函数的调用 简单的嵌套函数: 输出结果:
- HDU 5129 Yong Zheng's Death
题目链接:HDU-5129 题目大意为给一堆字符串,问由任意两个字符串的前缀子串(注意断句)能组成多少种不同的字符串. 思路是先用总方案数减去重复的方案数. 考虑对于一个字符串S,如图,假设S1,S2 ...
- webapi-2 接口参数
1. 实例 using System; using System.Collections.Generic; using System.Linq; using System.Net; using Sys ...
- (转)函数后面加const--C++ const成员函数
类的成员函数后面加 const,表明这个函数不会对这个类对象的数据成员(准确地说是非静态数据成员)作任何改变. 在设计类的时候,一个原则就是对于不改变数据成员的成员函数都要在后面加 const,而对于 ...
- Leetcode 之Length of Last Word(38)
做法很巧妙.分成左右两个对应的部分,遇到左半部分则入栈,遇到右半部分则判断对应的左半部分是否在栈顶.注意最后要判断堆栈是否为空. bool isValid(const string& s) { ...
- MAC Pro 2017款 无线上网慢
MAC Pro 2017款 在无线路由器和MAC相隔一个房间,上网很慢,怀疑是无线路由器有问题,但其他几台老款MAC和PC上网正常.后来将蓝牙关掉,上网就很快了.