位运算。。

。。

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. r语言之给定的概率密度函数生成随机数

    假设概率密度函数为: 思路: 首先产生-1到1之间的均匀分布随机数x,和0到1之间的均匀分布随机数y. 如果y<f(x),则x是符合该概率密度的随机数,否则,重复上述操作. 用r语言生成100个 ...

  2. ajax是怎么发请求的和浏览器发的请求一样吗?cookie

    下午设置cookie时出现了个问题 用ajax发的post请求php,在php的方法里设置了cookie,然后在浏览器请求的php里打印cookie值但是一直获取不到cookie的值 分析: 1.aj ...

  3. JAVA Metrics 度量工具使用介绍

    转载: http://blog.csdn.net/scutshuxue/article/details/8350135 http://koven2049.iteye.com/blog/968143 h ...

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

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

  5. Nginx Rewrite规则初探(转)

    Nginx  rewrite(nginx url地址重写)Rewrite 主要的功能就是实现URL的重写,Nginx的Rewrite规则采用Pcre,perl兼容正则表达式的语法规则匹配,如果需要Ng ...

  6. CloudStack修复bug

    CloudStack应用越来越广,但是随着测试也遇到了越来越多的bug. 不想等待新版本发布而且又急于修复某些bug的童鞋,可以参考下本文内容. CloudStack是java语言写成,发布时会发布为 ...

  7. mongodb 限制ip访问

    <pre name="code" class="python">一.限制访问IP和端口 MongoDB可以限制只允许某一特定IP来访问,只要在启动时 ...

  8. Excel连接到MySQL,将Excel数据导入MySql,MySQL for Excel,,

    Excel连接到MySQL 即使当今时代我们拥有了类似微软水晶报表之类的强大报表工具和其他一些灵活的客户管 理应用工具,众多企业在分析诸如销售统计和收入信息的时候,微软的Excel依然是最常用的工具. ...

  9. BZOJ 1600: [Usaco2008 Oct]建造栅栏

    1600: [Usaco2008 Oct]建造栅栏 Time Limit: 5 Sec  Memory Limit: 64 MB Description 勤奋的Farmer John想要建造一个四面的 ...

  10. CodeForces - 27E--Number With The Given Amount Of Divisors(反素数)

    CodeForces - 27E Number With The Given Amount Of Divisors Submit Status Description Given the number ...