UVALive 5059 C - Playing With Stones 博弈论Sg函数
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description
You and your friend are playing a game in which you and your friend take turns removing stones from piles. Initially there are N piles with a1, a2, a3,..., aN number of stones. On each turn, a player must remove at least one stone from one pile but no more than half of the number of stones in that pile. The player who cannot make any moves is considered lost. For example, if there are three piles with 5, 1 and 2 stones, then the player can take 1 or 2 stones from first pile, no stone from second pile, and only 1 stone from third pile. Note that the player cannot take any stones from the second pile as 1 is more than half of 1 (the size of that pile). Assume that you and your friend play optimally and you play first, determine whether you have a winning move. You are said to have a winning move if after making that move, you can eventually win no matter what your friend does.
Input
The first line of input contains an integer T(T
100) denoting the number of testcases. Each testcase begins with an integer N(1
N
100) the number of piles. The next line contains N integers a1, a2, a3,..., aN(1
ai
2 * 1018) the number of stones in each pile.
Output
For each testcase, print ``YES" (without quote) if you have a winning move, or ``NO" (without quote) if you don‟t have a winning move.
Sample Input
4
2
4 4
3
1 2 3
3
2 4 6
3
1 2 1
Sample Output
NO
YES
NO
YES
int n;
int main()
{
int t;
scanf("%d",&t);
while (t--){
scanf("%d",&n);
long long cnt=;
while (n--){
long long x;
scanf("%lld",&x);
if (x==) continue;
while (x&) x/=;
cnt^=x/;
}
if (cnt>) printf("YES\n");
else printf("NO\n");
}
return ;
}
UVALive 5059 C - Playing With Stones 博弈论Sg函数的更多相关文章
- uva1482:Playing With Stones (SG函数)
题意:有N堆石子,每次可以取一堆的不超过半数的石子,没有可取的为输. 思路:假设只有一堆,手推出来,数量x可以表示为2^p-1形式的必输. 但是没什么用,因为最后要的不是0和1,而是SG函数:所以必输 ...
- 【LA5059】Playing With Stones (SG函数)
题意:有n堆石子,分别有a[i]个.两个游戏者轮流操作,每次可以选一堆,拿走至少一个石子,但不能拿走超过一半的石子. 谁不能拿石子就算输,问先手胜负情况 n<=100,1<=a[i]< ...
- 【基础操作】博弈论 / SG 函数详解
博弈死我了……(话说哪个小学生会玩博弈论提到的这类弱智游戏,还取石子) 先推荐两个文章链接:浅谈算法——博弈论(从零开始的博弈论) 博弈论相关知识及其应用 This article was updat ...
- POJ2425 A Chess Game[博弈论 SG函数]
A Chess Game Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3917 Accepted: 1596 Desc ...
- bzoj1188 [HNOI2007]分裂游戏 博弈论 sg函数的应用
1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 973 Solved: 599[Submit][Status ...
- [BZOJ 1188] [HNOI2007] 分裂游戏 【博弈论|SG函数】
题目链接:BZOJ - 1188 题目分析 我们把每一颗石子看做一个单个的游戏,它的 SG 值取决于它的位置. 对于一颗在 i 位置的石子,根据游戏规则,它的后继状态就是枚举符合条件的 j, k.然后 ...
- [BZOJ 1874] [BeiJing2009 WinterCamp] 取石子游戏 【博弈论 | SG函数】
题目链接:BZOJ - 1874 题目分析 这个是一种组合游戏,是许多单个SG游戏的和. 就是指,总的游戏由许多单个SG游戏组合而成,每个SG游戏(也就是每一堆石子)之间互不干扰,每次从所有的单个游戏 ...
- 【GZOI2015】石子游戏 博弈论 SG函数
题目大意 有\(n\)堆石子,两个人可以轮流取石子.每次可以选择一堆石子,做出下列的其中一点操作: 1.移去整堆石子 2.设石子堆中有\(x\)个石子,取出\(y\)堆石子,其中\(1\leq y&l ...
- [2016北京集训试题6]魔法游戏-[博弈论-sg函数]
Description Solution 首先,每个节点上的权值可以等价于该节点上有(它的权的二进制位数+1)个石子,每次可以拿若干个石子但不能不拿. 然后就发现这和NIM游戏很像,就计算sg函数em ...
随机推荐
- 好用的工具---screen命令
问 题场景:要在服务器上配置环境,但是我的电脑无法直接连到服务器上,通常要经过好几次ssh跳转.配环境需要设置好几个用户,这自然需要同时打开好几个连 接服务器的终端窗口,每个连接到服务器的终端窗口都要 ...
- mac 下安装pip
pip是常用的Python包管理工具,类似于Java的maven.用python的同学,都离不开pip. 在新mac中想用home-brew安装pip时,遇到了一些小问题: bogon:~ wangl ...
- 常见四大类型视频接线DP、HDMI、DVI、VGA的比较
如今是新的“视”界,生活中总与各种屏幕打交道,难免会遇到选择视频接线的问题,要想搞清楚这点,我们只要通过了解现今常用的几种视频接线就会有个大致的认识. 281VGA.DVI.HDMI三种视频信号接 ...
- No.11 selenium学习之路之浏览器大小
通过set_window_size()方法可以设置打开的浏览器大小 maximize_window()方法可以把当前浏览器最大化 例子:
- HDU 4632 Palindrome subsequence(区间DP求回文子序列数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题目大意:给你若干个字符串,回答每个字符串有多少个回文子序列(可以不连续的子串).解题思路: 设 ...
- java jps命令使用解析
在linux环境下显示一个进程的信息大家可能一直都在使用ps命令,比如用以下命令来显示当前系统执行的java进程: ps -ef | grep java 针对java的进程,jdk1.5以后提供了一个 ...
- Robots.txt 不让搜索引擎收录网站的方法
有没有担心过自己的隐私会在强大的搜索引擎面前无所遁形?想象一下,如果要向世界上所有的人公开你的私人日记,你能接受吗?的确是很矛盾的问题,站长们大都忧虑“如何让搜索引擎收录的我的网站?”,而我们还是要研 ...
- Monaco Editor 使用入门
以前项目是用ace编辑器的,但是总有些不敬人意的地方.前端事件看见的VS Code编辑器Monaco Editor准备更换下,下面介绍一些使用中遇到的一点问题.代码提示 1.项目引用 import * ...
- 【LOJ】 #2540. 「PKUWC2018」随机算法
题解 感觉极其神奇的状压dp \(dp[i][S]\)表示答案为i,然后不可选的点集为S 我们每次往答案里加一个点,然后方案数是,设原来可以选的点数是y,新加入一个点后导致了除了新加的点之外x个点不能 ...
- python之markdown转html
python之markdown转html 为了方便,定义一个markdown转html的函数,直接调用即可 import markdown def md2html(mdstr): exts = ['m ...