位运算。。

。。

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. Android——用户登陆及用户名和密码的保存

    Android——用户登陆及用户名和密码的保存   在之前的学习过程中已经将Android学习完了,但是在后面将近一年的时间里都没有进行过Android开发,所以对Android的所有的知识点又有点忘 ...

  2. thinkphp小技巧

    if(IS_POST) _404("页面不存在",U("index"))               //如果不是POST提交,则跳转到index.debug模 ...

  3. Spark Streaming连接TCP Socket

    1.Spark Streaming是什么 Spark Streaming是在Spark上建立的可扩展的高吞吐量实时处理流数据的框架,数据可以是来自多种不同的源,例如kafka,Flume,Twitte ...

  4. 导出Excel并下载,但无法定制样式的方法!

    拿来的,望原创见谅! public void EXCELDown(DataTable dt, string strFileName) { Response.ContentEncoding = Syst ...

  5. sun.proxy.$Proxy0 cannot be cast to dao.impl.MyAdviceImpl

    ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");       ...

  6. 转: seajs知识点与cmd规范

    在比较之前,我们得先来了解下什么是AMD规范?什么是CMD规范?当然先申明一下,我个人也是总结下而已,也是网上看到的资料,自己总结下或者可以说整理下而已,供大家更深入的了解!因为我们都知道 AMD规范 ...

  7. 基于Qt下移动平台第三方接入-ShareSDK(新浪微博,微信朋友圈等分享登录)

    一. ShareSDK简介 ShareSDK是为iOS.Android.WP8的APP提供社会化功能的一个组件,开发者只需10分钟即 可集成到自己的APP中,它不仅支持如QQ.微信.新浪微博.腾讯微博 ...

  8. Java调用Python脚本

    今天遇到Java调用一个Python脚本的问题,纠结了大半天,遇到各种问题.网上搜索的大部分都是用jython,但是我想要调用的python脚本里有import urllib,这个urllib也不是什 ...

  9. android 项目中log信息的正确处理

    我们在做项目中,调试程序的时候通常是debug或者打log,特别是看一些json数据之类的,都喜欢打log看看,可是在项目上线时log信息一定不能被打印出来,大家能够平时下载一些做的烂的app,连接e ...

  10. 介绍一款开源的类Excel电子表格软件

     Excel一直以霸主的地位,占领了Windows桌面表格软件市场No 1,与此同一时候,Office套装产品差点儿成为了IT行业的标配办公技能.有无相似Excel的桌面程序,绿色版,实现主要的数 ...