Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap. 
---Wikipedia

Today, Nim takes revenge on you, again. As you know, the rule of Nim game is rather unfair, only the nim-sum (♁) of the sizes of the heaps is zero will the first player lose. To ensure the fairness of the game, the second player has a chance to move some (can be zero) heaps before the game starts, but he has to move one heap entirely, i.e. not partially. Of course, he can’t move all heaps out, at least one heap should be left for playing. Will the second player have the chance to win this time?

InputThe first line contains a single integer T, indicating the number of test cases.

Each test case begins with an integer N, indicating the number of heaps. Then N integer Ai follows, indicating the number of each heap.

[Technical Specification] 
1. 1 <= T <= 100 
2. 1 <= N <= 1 000 
3. 1 <= Ai <= 1 000 000 000 000OutputFor each test case, output “Yes” if the second player can win by moving some (can be zero) heaps out, otherwise “No”.Sample Input

3
1
2
3
2 2 2
5
1 2 3 4 5

Sample Output

No
Yes
Yes

Hint

For the third test case, the second player can move heaps with 4 and 5 objects out, so the nim-sum of the sizes of the left heaps is 1♁2♁3 = 0.
        

把上一题的S改为0即可。依然占位。

#include<bits/stdc++.h>
#define lowbit(x) (x&-x)
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
ll a[maxn],x1[maxn],x2[maxn],c[];
int main()
{
int T,N,cnt;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
rep(i,,N) scanf("%lld",&a[i]);
if(N==) puts("No");
else {
ll S=; cnt=;
rep(i,,) c[i]=;
rep(i,,N){
rep(j,,cnt){
if(a[i]&lowbit(c[j])) a[i]^=c[j];
}if(a[i]!=) c[++cnt]=a[i];
}
rep(i,,cnt) if(S&lowbit(c[i])) S^=c[i];
if(S!=||cnt==N) puts("No");
else puts("Yes");
}
}
return ;
}

HDU - 5088: Revenge of Nim II (问是否存在子集的异或为0)的更多相关文章

  1. HDOJ 5088 Revenge of Nim II 位运算

    位运算.. .. Revenge of Nim II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  2. HDU5088——Revenge of Nim II(高斯消元&矩阵的秩)(BestCoder Round #16)

    Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players tak ...

  3. HDU - 4994 Revenge of Nim (取石子游戏)

    Problem Description Nim is a mathematical game of strategy in which two players take turns removing ...

  4. hdu 5087 Revenge of LIS II

    http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意求第二长的上升序列. 在求最长上升序列的同时加上一个数组,来记录以i为结尾的有多少条序列.如果n+1为 ...

  5. hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)

    链接:hdu 5087 题意:求第二大的最长升序子序列 分析:这里的第二大指的是,全部的递增子序列的长度(包含相等的), 从大到小排序后.排在第二的长度 cid=546" style=&qu ...

  6. HDU 5078 Revenge of LIS II(dp LIS)

    Problem Description In computer science, the longest increasing subsequence problem is to find a sub ...

  7. hdu 5087 Revenge of LIS II (DP)

    题意: N个数,求第二长上升子序列的长度. 数据范围: 1. 1 <= T <= 1002. 2 <= N <= 10003. 1 <= Ai <= 1 000 0 ...

  8. CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)

    As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initi ...

  9. hdu 5088 高斯消元n堆石子取k堆石子使剩余异或值为0

    http://acm.hdu.edu.cn/showproblem.php?pid=5088 求能否去掉几堆石子使得nim游戏胜利 我们可以把题目转化成求n堆石子中的k堆石子数异或为0的情况数.使用x ...

随机推荐

  1. jst格式化日期

    jsp页面需引入fmt标签:<taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"> ...

  2. 【Flask】Flask Cookie操作

    ### 什么是cookie:在网站中,http请求是无状态的.也就是说即使第一次和服务器连接后并且登录成功后,第二次请求服务器依然不能知道当前请求是哪个用户.cookie的出现就是为了解决这个问题,第 ...

  3. GIT使用—一些概念

    (1)Git版本库(repository) 一个简单的数据库,包括所有用来维护与管理项目的修订版本和历史的信息. Git维护两个主要的数据结构: 对象库(object store)-在复制操作时能进行 ...

  4. 防止CSRF的攻击—Origin和Referer

    防止CSRF的攻击—Origin和Referer 为了防止CSRF的攻击,我们建议修改浏览器在发送POST请求的时候加上一个Origin字段,这个Origin字段主要是用来标识出最初请求是从哪里发起的 ...

  5. Ubuntu 14.04上架IPSec+L2TP的方法

    最简单的方法是使用脚本一步一步地进行配置.我用的是philplckthun写的脚本,修改了一下获取服务器IP的方法:脚本文件. 在ubuntu下运行: sh setup.sh 配置配置完成后,服务器端 ...

  6. J2EE--Hibernate基础笔记

    因为写的是基础内容,所以在这里,(映射集合.映射组件.复合主键和联合主键,jpa annotation,关联映射,hql等等实用内容)都不会提到- 这里写的就是试用李刚<J2EE实战>那本 ...

  7. Linux常用监控命令

    A goal is a dream with a deadline. Much effort, much prosperity.  1.IOSTAT命令 此命令安装包为sysstat     可用yu ...

  8. HDU 5704

    题意:n个人参加一个游戏,每个人选择0-100范围的数.m为选择的所有数的平均数*2/3,选择的数<=m且距离m最近的人获胜,若同时有多人满足条件则随机抽取胜者.如果一个人选的数,比m小,且相距 ...

  9. idea软件编码已经设置好了为utf-8,但是svn中down下来的文件格式本身不是utf-8的,此时打开后会出现中文乱码解决方法

    我是个idea的忠实用户,新公司的项目都是用eclipse做的,通过svn拉下代码后发现,注释的内容里,中文内容都是乱码.问过项目负责人,说可能是GBK编码. 但是,我通过idea的setting设置 ...

  10. 使用SpringMVC时报错HTTP Status 405 - Request method 'GET' not supported

    GET方法不支持.我出错的原因在于,在JSP中我希望超链接a以post方式提交,但是这里写js代码时出错. <script type="text/javascript"> ...