HDOJ 5088 Revenge of Nim II 位运算
位运算。。
。。
Revenge of Nim II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 229 Accepted Submission(s): 79
---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?
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 000
3
1
2
3
2 2 2
5
1 2 3 4 5
No
Yes
YesHintFor 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.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long int LL; int n;
LL c[60];
LL a[1100]; int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
memset(c,0,sizeof(c));
scanf("%d",&n);
for(int i=1;i<=n;i++)
cin>>a[i];
bool flag=false;
for(int i=1;i<=n;i++)
{
for(int j=60;j>=0;j--)
{
if(c[j]==0&&(a[i]&(1LL<<j)))
{
c[j]=a[i];
break;
}
else if(a[i]&(1LL<<j))
{
a[i]^=c[j];
if(a[i]==0) flag=true;
}
}
}
if(flag==true) puts("Yes");
else puts("No");
}
return 0;
}
HDOJ 5088 Revenge of Nim II 位运算的更多相关文章
- 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 ...
- hdoj 5087 Revenge of LIS II 【第二长单调递增子】
称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O ...
- 剑指 Offer 56 - II. 数组中数字出现的次数 II + 位运算
剑指 Offer 56 - II. 数组中数字出现的次数 II Offer_56_2 题目详情 解题思路 java代码 package com.walegarrett.offer; /** * @Au ...
- HDOJ 5087 Revenge of LIS II DP
DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- HDU - 5088: Revenge of Nim II (问是否存在子集的异或为0)
Nim is a mathematical game of strategy in which two players take turns removing objects from distinc ...
- leetcode Single Number II - 位运算处理数组中的数
题目描述: 给定一个包含n个整数的数组,除了一个数出现一次外所有的整数均出现三次,找出这个只出现一次的整数. 题目来源: http://oj.leetcode.com/problems/single- ...
- [LeetCode] Single Number II 位运算
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 【leetcode】Single Number && Single Number II(ORZ 位运算)
题目描述: Single Number Given an array of integers, every element appears twice except for one. Find tha ...
- codeforces - 15C Industrial Nim(位运算+尼姆博弈)
C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...
随机推荐
- Joel在耶鲁大学的演讲
Joel Spolsky是一个美国的软件工程师,他的网络日志"Joel谈软件"(Joel on Software)非常有名,读者人数可以排进全世界前100名. 上个月28号,他回到 ...
- Aptana Studio 3 官方汉化包汉化
Babel Language Pack Update Site for Helios This URL is an Eclipse software repository:http://downloa ...
- C语言新学备忘_1
#include <stdio.h> //C语言的标准输入 ,输出头文件扩展名为.h的文件称为头文件 //include称为文件包含命令 #include <stdlib.h> ...
- 高级UNIX环境编程
常规文件 只有索引节号(i-number,是一批i-node的索引),i-node不含文件名及数据字节,包括文件类型,链接数量,uid,gid,访问权限,字节数,最后访问时间,最后修改时间,信息节点最 ...
- 转: ajax跨域之JSONP
事件背景: 某个站点分为静态产品介绍页面(或由于某原因需要静态化),和一个独立的在线应用程序.静态产品页面属于www.a.com下,而在线应用程序作为一个相对独立的系统存在于app.a.com上. 在 ...
- AnsiString 在 Delphi 中虽然不可用,但是,在 C++ 中可以用
[C++] C++ Builder 中 Ansi 编码的字符串在Android/iOS程序中显示的问题 呃,这个问题说起来,其实也不麻烦,C++ Builder 本身在 TEncoding 做了处理, ...
- ZigBee研究之旅(二)
在学习ZigBee设备CC2530模块时,编程后程序无法运行,但又十分确定程序的真确性的情况下,看看是不是project栏下的option选项配置的有问题,我是经常在这里出问题,一开始找不到原因,特此 ...
- ThinkPHP - CURD增删改查操作
public function show(){ //使用model模型 //1.可以使用 $user = new Model('User'); //2.可以使用 $user = M('User'); ...
- Hibernate 多对一
Hibernate的many-to-one 关联. 具体看配置文件: <?xml version="1.0"?> <!DOCTYPE hibernate-mapp ...
- 利用SolrJ操作solr API完成index操作
使用SolrJ操作Solr会比利用httpClient来操作Solr要简单.SolrJ是封装了httpClient方法,来操作solr的API的.SolrJ底层还是通过使用httpClient中的方法 ...