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. 跟着实例学习ZooKeeper的用法: 分布式锁

    锁 分布式的锁全局同步, 这意味着任何一个时间点不会有两个客户端都拥有相同的锁. 可重入锁Shared Reentrant Lock 首先我们先看一个全局可重入的锁. Shared意味着锁是全局可见的 ...

  2. case的嵌套使用

    case分支语句的格式如下: case $变量名 in 模式1) 命令序列1 ;; 模式2) 命令序列2 ;; *) 默认执行的命令序列     ;; esac case语句结构特点如下: 1.    ...

  3. ddt运行报错AttributeError: type object 'TestLogin' has no attribute 'test_login'

    源代码: #!usr/bin/python3 # -*- coding:utf-8 -*- # @Time: 2018/12/17 下午2:07 # @File: do_excel.py # @Sof ...

  4. html 5中的新特性之强化表单元素及属性

    之前我们判断用户提交的是否是Email 的时候,往往使用js 进行判断,但在html5中可以有新的方式进行判断而且更简单 <!DOCTYPE html> <html lang=&qu ...

  5. Linux常用监控命令

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

  6. 线段树的lazy(poj3468)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 73163   ...

  7. 偶然发现有的IIS里的程序,连接 不上SQL Server数据库, 超时

    经查应用程序池中, 有一个启用32位应用程序,  有时打开它就能连接上SQL SERVER了.

  8. Oozie java.io.IOException: output.properties data exceeds its limit [2048]

    在使用oozie调用sqoop时,报了下边这个错 Launcher AM execution failed java.io.IOException: output.properties data ex ...

  9. 用idea编译器写第一个Java程序——步骤

  10. DPDK l3fwd

    l3fwd负责三层转发,比l2fwd要复杂点. /*- * BSD LICENSE * * Copyright(c) 2010-2014 Intel Corporation. All rights r ...