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函数,暴力一遍,打表 ...
随机推荐
- 基本控件文档-UIButton属性---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...
- jq 浏览器窗口大小发生变化时
当调整浏览器窗口的大小时,发生 resize 事件: $(selector).resize(); 实例 对浏览器窗口调整大小进行计数: $(window).resize(function() { $( ...
- github新建托管项目及上传项目
一.新建托管项目 1.注册: 2.点击new repositories新建一个新项目: 3.输入项目名称及项目描述,Create repository: 4.点击右边栏的剪切板图标,记录下你的项目地址 ...
- LeetCode 20 Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- source insight 保存时删除多余空格,去除多余空格 space tab键【转】
转自:http://blog.csdn.net/lanmanck/article/details/8638391 上传源码时最好把空格行去掉,以前介绍了使用notepad++,现在发现,习惯用sour ...
- 看jquery3.3.1学js类型判断的技巧
需要预习:call , typeof, js数据类型 1. isFunction中typeof的不靠谱 源码: var isFunction = function isFunction( obj ) ...
- binlog_server备份binlogs
在主库上建一个复制用的账号: root@localhost [(none)]>grant replication slave on *.* to 'wyz'@'%' identified by ...
- Java Redis 连接池 Jedis 工具类
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.Jedis; import re ...
- Mysql 数据库学习笔记01查询
1.数据查询基本操作 * 正则表达式查询: 字段名 regexp '匹配方式', select * from user where username regexp '^名' -- 查询 姓名 名 ...
- Leetcode 之Regular Expression Matching(31)
正则表达式的匹配,还是挺难的.可根据下一个字符是不是*分为两种情况处理,需要考虑多种情况. bool isMatch(const char *s, const char *p) { if (*p == ...