位运算。。

。。

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

Problem Description
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?

 
Input
The 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 000
 
Output
For 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.
 
Source
 

#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 位运算的更多相关文章

  1. 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 ...

  2. hdoj 5087 Revenge of LIS II 【第二长单调递增子】

    称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O ...

  3. 剑指 Offer 56 - II. 数组中数字出现的次数 II + 位运算

    剑指 Offer 56 - II. 数组中数字出现的次数 II Offer_56_2 题目详情 解题思路 java代码 package com.walegarrett.offer; /** * @Au ...

  4. HDOJ 5087 Revenge of LIS II DP

    DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  5. HDU - 5088: Revenge of Nim II (问是否存在子集的异或为0)

    Nim is a mathematical game of strategy in which two players take turns removing objects from distinc ...

  6. leetcode Single Number II - 位运算处理数组中的数

    题目描述: 给定一个包含n个整数的数组,除了一个数出现一次外所有的整数均出现三次,找出这个只出现一次的整数. 题目来源: http://oj.leetcode.com/problems/single- ...

  7. [LeetCode] Single Number II 位运算

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  8. 【leetcode】Single Number && Single Number II(ORZ 位运算)

    题目描述: Single Number Given an array of integers, every element appears twice except for one. Find tha ...

  9. codeforces - 15C Industrial Nim(位运算+尼姆博弈)

    C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...

随机推荐

  1. BZOJ 1711: [Usaco2007 Open]Dingin吃饭( 最大流 )

    将牛拆成两个点 i 和 i' 并连弧 , S 向每种 food 连边 , 每种 drink 向 T 连边 , 每种 food 向喜欢他的 cow 连边 到 i , 每种 drink 从喜欢它的 cow ...

  2. 3,C语言文件读写

    这两天看到一个关于文件读写的题目,索性就把相关内容总结下. C语言文件读写,无非是几个读写函数的应用,fopen(),fread(),fwrite()等,下面简单介绍下. 一.fopen() 函数原型 ...

  3. Apache BeanUtils 1.9.2 官方入门文档

    为什么需要Apache BeanUtils? Apache BeanUtils 是 Apache开源软件组织下面的一个项目,被广泛使用于Spring.Struts.Hibernate等框架,有数千个j ...

  4. css中border-width 属性

    border-width属性可能的值 值 描述 thin 定义细的边框. medium 默认.定义中等的边框. thick 定义粗的边框. length 允许您自定义边框的宽度. inherit 规定 ...

  5. Object 保存到文件中

    6月4日 Object 保存到文件中  Q. 你添加一个新类到你的项目当中且你希望可以保存这个类的一个实例对象到磁盘文件 并在需要时从磁盘文件读回到内存中  A. 方案  确保你的类遵循 NSCodi ...

  6. BZOJ 1798: [Ahoi2009]Seq 维护序列seq( 线段树 )

    线段树.. 打个 mul , add 的标记就好了.. 这个速度好像还挺快的...( 相比我其他代码 = = ) 好像是#35.. ---------------------------------- ...

  7. YII重点文件

    yii\di\Containeryii\base\Componentyii\base\Objectyii\base\Configurableyii\web\Applicationyii\base\Ap ...

  8. 4.I/O复用以及基于I/O复用的回射客户端/服务器

    I/O复用:当一个或多个I/O条件满足时,我们就被通知到,这种能力被称为I/O复用. 1.I/O复用的相关系统调用 posix的实现提供了select.poll.epoll两类系统调用以及相关的函数来 ...

  9. ASP.NET MVC 5 学习教程:生成的代码详解

    原文 ASP.NET MVC 5 学习教程:生成的代码详解 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 创建连接字符串 ...

  10. docker学习笔记18:Dockerfile 指令 VOLUME 介绍

    在介绍VOLUME指令之前,我们来看下如下场景需求: 1)容器是基于镜像创建的,最后的容器文件系统包括镜像的只读层+可写层,容器中的进程操作的数据持久化都是保存在容器的可写层上.一旦容器删除后,这些数 ...