HDU - 5088: Revenge of Nim II (问是否存在子集的异或为0)
---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)的更多相关文章
- HDOJ 5088 Revenge of Nim II 位运算
位运算.. .. Revenge of Nim II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 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 ...
- HDU - 4994 Revenge of Nim (取石子游戏)
Problem Description Nim is a mathematical game of strategy in which two players take turns removing ...
- hdu 5087 Revenge of LIS II
http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意求第二长的上升序列. 在求最长上升序列的同时加上一个数组,来记录以i为结尾的有多少条序列.如果n+1为 ...
- hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)
链接:hdu 5087 题意:求第二大的最长升序子序列 分析:这里的第二大指的是,全部的递增子序列的长度(包含相等的), 从大到小排序后.排在第二的长度 cid=546" style=&qu ...
- HDU 5078 Revenge of LIS II(dp LIS)
Problem Description In computer science, the longest increasing subsequence problem is to find a sub ...
- hdu 5087 Revenge of LIS II (DP)
题意: N个数,求第二长上升子序列的长度. 数据范围: 1. 1 <= T <= 1002. 2 <= N <= 10003. 1 <= Ai <= 1 000 0 ...
- 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 ...
- hdu 5088 高斯消元n堆石子取k堆石子使剩余异或值为0
http://acm.hdu.edu.cn/showproblem.php?pid=5088 求能否去掉几堆石子使得nim游戏胜利 我们可以把题目转化成求n堆石子中的k堆石子数异或为0的情况数.使用x ...
随机推荐
- Spark机器学习7·降维模型(scala&python)
PCA(主成分分析法,Principal Components Analysis) SVD(奇异值分解法,Singular Value Decomposition) http://vis-www.cs ...
- Zabbix 自定义Key
系统:Linux Centos 7.4 x64.Windos 2008 x64 服务:Zabbix 3.0.16 说明1:自定义Key 主要通过自定义 脚本 或者 命令 来实现自定义监控类型,需要在a ...
- 20145219 《Java程序设计》实验三 敏捷开发与XP实践
20145219 <Java程序设计>实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验步骤 敏捷开发与XP 1.敏捷开发(Agile Development)是 ...
- Mac & Xcode 技巧
1.Xcode 删除过期的Provisioning Profile文件 解决:Xcode 中所有的Provisioning Profile文件路径,都在 ~/Library/MobileDevice/ ...
- TRUNC函数的用法
TRUNC函数用于对值进行截断. 用法有两种:TRUNC(NUMBER)表示截断数字,TRUNC(date)表示截断日期. (1)截断数字: 格式:TRUNC(n1,n2),n1表示被截断的数字,n2 ...
- java 客户端发起http请求2
客户端请求方式一,如果数据类型为 x-www-form-urlencoded 用到的json jar包为 gradle ('com.alibaba:fastjson:1.2.38',) 那么对应的代码 ...
- 使用VBS打开程序和关闭程序
下面这个是先执行程序后,然后再结束程序. Dim Wsh Set Wsh = WScript.CreateObject("WScript.Shell") '下行是设置延时启动时间 ...
- Mac安装搭建sublimeText3开发Nodejs环境
原文] [基本环境 安装Nodejs 这个直接就可以去官网下载就可以了.Nodejs官网 根据自己的PC系统类型选择对应的版本下载之后就可以了. 安装SublimeText3 这个也是直接去Subli ...
- Maven添加Oracle驱动及依赖
oracle驱动先去官网下载,下载下来后,需要安装到maven本地仓库,然后再pom中添加依赖. 1下载oracle驱动包 ojdbc6-11.2.0.3.jar 2命令行安装到maven仓库 mvn ...
- vector push_back数量大的时候变慢
才用15000个数据 push_back耗时就好几秒, 解决方法是 先resize 15000, 然后再 for (int i = 0; i < 15000; i++) { Data data ...