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. opencms研究笔记

    最近公司一新产品,众多选型之后: 最后还是准备在用opencms 在opencms的基础上,进行二次开发: 有一起研究的没 欢迎交流:

  2. php 变量的8类类型

    整形,布尔,浮点形,字符串,数组,资源,对象和null php数据类型之查看和判断数据类型 php数据类型之自动转换和强制转换

  3. html页面 加载完成后再刷新 一次

    主要用于第一次加载页面有部分加载bug,再刷新一次即可正常运行. 简单粗暴直接上代码,不带参数,0影响 <Script>function refresh(){ url = location ...

  4. Linux段式管理与页式管理

    内存管理有2种机制:1.段式管理:2.页式管理 在80386CPU中增加了2个寄存器:1.全局性的段描述表寄存器GDTR 2.局部性的段描述表寄存器LDTR 段寄存器的高13位用于在全局或局部描述表项 ...

  5. 守护进程,进程安全,IPC进程间通讯,生产者消费者模型

    1.守护进程(了解)2.进程安全(*****) 互斥锁 抢票案例3.IPC进程间通讯 manager queue(*****)4.生产者消费者模型 守护进程 指的也是一个进程,可以守护着另一个进程 一 ...

  6. Android面试收集录13 Android虚拟机及编译过程

    一.什么是Dalvik虚拟机 Dalvik是Google公司自己设计用于Android平台的Java虚拟机,它是Android平台的重要组成部分,支持dex格式(Dalvik Executable)的 ...

  7. Spring---配置文件概述

    概述 Spring 的配置文件是用于指导 Spring 工厂进行Bean的生产.依赖关系注入及 Bean 实例分发的“图纸”,它是一个或多个标准的XML文档,J2EE 程序员必须学会并灵活应用这份“图 ...

  8. ThinkPad 触控板双指不可以滑动

    我一直在想为什么,今天我想禁用触摸板的时候,我找到原因了. 是因为没有装驱动. http://think.lenovo.com.cn/support/driver/newdriversdownlist ...

  9. elasticsearch索引和映射

    目录 1. elasticsearch如何实现搜索 1.1 搜索实例 1.2 es中数据的类型 1.3 倒排索引 1.4 分析与分析器 1.4.1 什么是分析器 1.4.2 内置分析器种类 1.4.3 ...

  10. Redis常用知识

    1.redis是什么 redis是一种支持Key-Value等多种数据结构的存储系统.可用于缓存.事件发布或订阅.高速队列等场景.该数据库使用ANSI C语言编写,支持网络,提供字符串.哈希.列表.队 ...