C - Playing With Stones

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(T100) denoting the number of testcases. Each testcase begins with an integer N(1N100) the number of piles. The next line contains N integers a1, a2, a3,..., aN(1ai2 * 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函数的更多相关文章

  1. uva1482:Playing With Stones (SG函数)

    题意:有N堆石子,每次可以取一堆的不超过半数的石子,没有可取的为输. 思路:假设只有一堆,手推出来,数量x可以表示为2^p-1形式的必输. 但是没什么用,因为最后要的不是0和1,而是SG函数:所以必输 ...

  2. 【LA5059】Playing With Stones (SG函数)

    题意:有n堆石子,分别有a[i]个.两个游戏者轮流操作,每次可以选一堆,拿走至少一个石子,但不能拿走超过一半的石子. 谁不能拿石子就算输,问先手胜负情况 n<=100,1<=a[i]< ...

  3. 【基础操作】博弈论 / SG 函数详解

    博弈死我了……(话说哪个小学生会玩博弈论提到的这类弱智游戏,还取石子) 先推荐两个文章链接:浅谈算法——博弈论(从零开始的博弈论) 博弈论相关知识及其应用 This article was updat ...

  4. POJ2425 A Chess Game[博弈论 SG函数]

    A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3917   Accepted: 1596 Desc ...

  5. bzoj1188 [HNOI2007]分裂游戏 博弈论 sg函数的应用

    1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 973  Solved: 599[Submit][Status ...

  6. [BZOJ 1188] [HNOI2007] 分裂游戏 【博弈论|SG函数】

    题目链接:BZOJ - 1188 题目分析 我们把每一颗石子看做一个单个的游戏,它的 SG 值取决于它的位置. 对于一颗在 i 位置的石子,根据游戏规则,它的后继状态就是枚举符合条件的 j, k.然后 ...

  7. [BZOJ 1874] [BeiJing2009 WinterCamp] 取石子游戏 【博弈论 | SG函数】

    题目链接:BZOJ - 1874 题目分析 这个是一种组合游戏,是许多单个SG游戏的和. 就是指,总的游戏由许多单个SG游戏组合而成,每个SG游戏(也就是每一堆石子)之间互不干扰,每次从所有的单个游戏 ...

  8. 【GZOI2015】石子游戏 博弈论 SG函数

    题目大意 有\(n\)堆石子,两个人可以轮流取石子.每次可以选择一堆石子,做出下列的其中一点操作: 1.移去整堆石子 2.设石子堆中有\(x\)个石子,取出\(y\)堆石子,其中\(1\leq y&l ...

  9. [2016北京集训试题6]魔法游戏-[博弈论-sg函数]

    Description Solution 首先,每个节点上的权值可以等价于该节点上有(它的权的二进制位数+1)个石子,每次可以拿若干个石子但不能不拿. 然后就发现这和NIM游戏很像,就计算sg函数em ...

随机推荐

  1. numpy细碎知识点

    np.random.rand() 基于python自带模块random的random函数的一个延伸吧,生成指定数量的列表 np.random.rand(a,b) 参数a,b均为整型,生成含有a个元素的 ...

  2. lombok java代码助手

    是不一个不错的代码生成工具,可以实现将代码更精简,且不失代码效率的一种不错的方法 https://www.cnblogs.com/qnight/p/8997493.html 通过java bean v ...

  3. DevExpress GridControl 的数据绑定

    本人不才啊,折腾2个多小时才把数据绑定好.现在把折腾过程记录一下来以帮助更多的朋友,自己也温习一下. 直接上代码了哈.... WPF哈 xaml文件 <dxg:GridControl Name= ...

  4. Scrapy命令行工具简介

    Windows 10家庭中文版,Python 3.6.4,virtualenv 16.0.0,Scrapy 1.5.0, 在最初使用Scrapy时,使用编辑器或IDE手动编写模块来创建爬虫(Spide ...

  5. python基础--类的经典类vs新式类

    经典类VS新式类区别 1)写法新式类class Person(object):#new style 经典类class Persion: #classical style 2)调用父类 新式写法用sup ...

  6. C实现线程池

    简介:这里使用linux下的互斥锁和条件变量实现了一个线程池.代码由一个未知作者完成,第二任作者补充优化. 本人仅仅是做了一些注释工作. 代码如下: /*! .h */ #include <st ...

  7. malloc和free的实现

     C++ Code  12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...

  8. centos7.x firewall简单使用

    开放一个端口: firewall-cmd --zone=public --add-port=22/tcp –permanent 开放一个范围端口对外部所有地址生效: firewall-cmd --zo ...

  9. java 工厂模式和内部类的完美结合

    package com.bikeqx.test; public class Main{ public static void apply(ServiceFactory sf){ Service s = ...

  10. Django学习笔记--通用列表和详细信息视图

    根据教程写完代码后,点击All books也一直跳转到index的页面 我打开了F12调试,看到点击没有出现book_list的代码,觉得应该是url的路径写得不对,但是跟教程代码对比了下,并没有发现 ...