Stone Game II comes. It needs two players to play this game. There are some piles of stones on the desk at the beginning. Two players move the stones in turn. At each step of the game the player should do the following operations.
  First, choose a pile of stones. (We assume that the number of stones in this pile is n)

  Second, take some stones from this pile. Assume the number of
stones left in this pile is k. The player must ensure that 0 < k <
n and (k XOR n) < n, otherwise he loses.

  At last, add a new pile of size (k XOR n). Now the player can
add a pile of size ((2*k) XOR n) instead of (k XOR n) (However, there is
only one opportunity for each player in each game).

The first player who can't do these operations loses. Suppose two
players will do their best in the game, you are asked to write a program
to determine who will win the game.

Input  The first line contains the number T of test cases
(T<=150). The first line of each test cases contains an integer
number n (n<=50), denoting the number of piles. The following n
integers describe the number of stones in each pile at the beginning of
the game.

You can assume that all the number of stones in each pile will not exceed 100,000.

Output  For each test case, print the case number and the answer.
if the first player will win the game print "Yes"(quotes for clarity) in
a single line, otherwise print "No"(quotes for clarity).

Sample Input

3
2
1 2
3
1 2 3
4
1 2 3 3

Sample Output

Case 1: No
Case 2: Yes
Case 3: No http://blog.csdn.net/y1196645376/article/details/52143551
 #pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring> #define N 27
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
}
int getone(int num)//得到一个数二进制中1的个数
{
int cnt = ;
while(num)
{
cnt += (num&);
num>>=;
}
return cnt;
}
int main()
{
int t,n,k,_case = ;
cin >> t;
while(t--)
{
cin >> n;
printf("Case %d: ",++_case);
k = ;
int step;
for(int i = ; i < n ; i ++)
{
scanf("%d",&step);
k += getone(step);
}
printf((k+n)&? "Yes\n":"No\n");
}
return ;
}

hdu 4388 Stone Game II sg函数 博弈的更多相关文章

  1. HDU 4388 Stone Game II {博弈||找规律}

    Stone Game II Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. hdu 4388 Stone Game II

    Stone Game II HDU - 4388 题目大意: 给出n堆物品,每堆物品都有若干件,现在A和B进行游戏,每人每轮操作一次,按照如下规则: 1. 任意选择一个堆,假设该堆有x个物品,从中选择 ...

  3. HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场

    题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...

  4. HDU 4388 Stone Game II 博弈论 找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=4388 http://blog.csdn.net/y1196645376/article/details/5214 ...

  5. HDU 1729 Stone Game【SG函数】

    以下转载至:长春理工大学赵小舟博弈论ppt 题目大意: 1.有n个盒子,每个盒子都有它的容量s 2.在游戏开始时,每个盒子里都有一些石子 3.双方轮流进行游戏,向一个盒子投入n个石子,其中n不能大于当 ...

  6. hdoj 1729 Stone Games(SG函数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1729 看了题目感觉像Nim,但是有范围限制,有点不知道SG函数该怎么写 看了题解,最后才明白该怎么去理 ...

  7. 博弈问题之SG函数博弈小结

    SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...

  8. HDU 1536 S-Nim (组合游戏+SG函数)

    题意:针对Nim博弈,给定上一个集合,然后下面有 m 个询问,每个询问有 x 堆石子 ,问你每次只能从某一个堆中取出 y 个石子,并且这个 y 必须属于给定的集合,问你先手胜还是负. 析:一个很简单的 ...

  9. SG函数博弈——poj2311

    关于SG函数的博弈 首先定义必败态 x : SG[x]=0 设任意一个状态y,到所有y能到达的状态连一条边,令这些后继为z y : SG[y]=mex(SG[z]) SG[y]==0 : y就是必败态 ...

随机推荐

  1. 在React Native中集成热更新

    最近,在项目DYTT集成了热更新,简单来说,就是不用重新下载安装包即可达到更新应用的目的,也不算教程吧,这里记录一下. 1.热更新方案 目前网上大概有两个比较广泛的方式,分别是 react-nativ ...

  2. 服务器缺少vcruntime140.dll,无法运行

    Redis用了一段时间,有的时候,调试的时候,RedisDesktop是个不错的工具 当我想在服务器上安装的时候,才发现服务器64位的环境里面运行出错了 百度上有共享dll出来的,但是基本都没法用,虽 ...

  3. (转)零基础学习 Hadoop 该如何下手?

    推荐一些Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pig, HBase, Sqoop, Mahout, Zookeeper, Avro, Amb ...

  4. stat.h头文件,轻松获取文件属性

    [以前还为了获取文件的长度,费劲从头读取一遍,一个一个字节的算. 做webserver时候,发现原来stat函数可以返回一个结构,里面包括文件的全部属性. 真是曲折啊.] #i nclude<s ...

  5. C语言进阶——类型转换04

    C语言内可以进行类型转换: 强制类型转换 隐式类型转换 强制类型转换的语法: (tpye)value (type)value_name 强制类型转换的结果: 目标类型可以容纳目标值:结果不变 目标值不 ...

  6. 使用Windows Live Writer写文章时不要用360清除垃圾

    ref:http://www.zhengsiwei.com/write-an-article-to-use-windows-live-writer-dont-use-360-to-remove-rub ...

  7. 将list中的元素按照属性分类成树状的map

    技术交流群: 233513714 public LinkedHashMap<String, List<TPhoneModel>> queryPhoneList(List< ...

  8. 使用Matrix-tree与它的行列式来解决生成树计数问题

    我又把Matrix写错啦 这东西讲课的时候竟然一笔带过了,淦 好吧这东西我不会证 那我们来愉快的看结论吧 啦啦啦 预备工作 你有一个 $ n $ 个点的图 比如说 5 /|\ / | \ 2--1-- ...

  9. swoole创建websocket服务器

    目录 1 安装准备 1.1 安装swoole前必须保证系统已经安装了下列软件 1.2 下载并解压 1.3 编译安装成功后,修改php.ini 2 构建Swoole基本实例 2.1 tcp服务器实例 2 ...

  10. ScrollView中ViewPager无法正常滑动问题

    本文主要介绍如何解决ViewPager在ScrollView中滑动经常失效.无法正常滑动问题. 解决方法只需要在接近水平滚动时ScrollView不处理事件而交由其子View(即这里的ViewPage ...