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 ...
随机推荐
- jQuery焦点图插件
在线演示 本地下载
- zabbix监控nginx的性能
1.nginx配置 需要使用zabbix监控nginx,首先nginx需要配置ngx_status,在nginx的配置文件中加入红框中的配置,然后重启nginx如下图所示: location /ngx ...
- 20145201 《Java程序设计》第二周学习总结
20145201 <Java程序设计>第二周学习总结 教材学习内容总结 本周学习了课本第三章内容,即JAVA基础语法. 3.1 类型.变量与运算符 基本类型:在java中基本类型主要可区分 ...
- 《 Python 学习手册 》读书笔记(1)
关于运行程序 交互提示模式下编写代码 terminal中直接输入python开启 通过导入模块,运行文件中的语句 import exec(open('module.py').read()) UNIX可 ...
- zabbix api
#!/usr/bin/env python # -*-coding:utf-8 -*- import requests import json class AutoZabbix: def __init ...
- 《Maven实战》第13章 版本管理
版本管理:项目整体版本的演变过程的管理,如从1.0-SNAPSHOT到1.0,再到1.1-SNAPSHOT 版本控制:借助版本控制工具追踪代码的每一个变更 13.1什么是版本管理 版本管理:项目整体版 ...
- idea中git合并切换分支等操作
https://blog.csdn.net/autfish/article/details/52513465
- 谷歌浏览器和火狐浏览器设置跨域和https、http混用 Chrome
谷歌浏览器和火狐浏览器设置跨域和https.http混用 Chrome 添加启动项: 右键点击Chrome快捷方式,在目标一栏后添加启动项 允许跨域: --disable-web-securit ...
- AtCoder Regular Contest 094
AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...
- MongoError: server instance in invalid state undefined 解决办法
MongoDB关键点集锦(更新中...) 2017-01-20 09:33:48[其它数据库]点击数:15作者:Real_Bird的博客来源: 网络 随机为您推荐的文章:MongDB索引的介绍及使用 ...