hdu 4388 Stone Game II sg函数 博弈
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.
(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函数 博弈的更多相关文章
- HDU 4388 Stone Game II {博弈||找规律}
Stone Game II Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 4388 Stone Game II
Stone Game II HDU - 4388 题目大意: 给出n堆物品,每堆物品都有若干件,现在A和B进行游戏,每人每轮操作一次,按照如下规则: 1. 任意选择一个堆,假设该堆有x个物品,从中选择 ...
- HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场
题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...
- HDU 4388 Stone Game II 博弈论 找规律
http://acm.hdu.edu.cn/showproblem.php?pid=4388 http://blog.csdn.net/y1196645376/article/details/5214 ...
- HDU 1729 Stone Game【SG函数】
以下转载至:长春理工大学赵小舟博弈论ppt 题目大意: 1.有n个盒子,每个盒子都有它的容量s 2.在游戏开始时,每个盒子里都有一些石子 3.双方轮流进行游戏,向一个盒子投入n个石子,其中n不能大于当 ...
- hdoj 1729 Stone Games(SG函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1729 看了题目感觉像Nim,但是有范围限制,有点不知道SG函数该怎么写 看了题解,最后才明白该怎么去理 ...
- 博弈问题之SG函数博弈小结
SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...
- HDU 1536 S-Nim (组合游戏+SG函数)
题意:针对Nim博弈,给定上一个集合,然后下面有 m 个询问,每个询问有 x 堆石子 ,问你每次只能从某一个堆中取出 y 个石子,并且这个 y 必须属于给定的集合,问你先手胜还是负. 析:一个很简单的 ...
- SG函数博弈——poj2311
关于SG函数的博弈 首先定义必败态 x : SG[x]=0 设任意一个状态y,到所有y能到达的状态连一条边,令这些后继为z y : SG[y]=mex(SG[z]) SG[y]==0 : y就是必败态 ...
随机推荐
- JavaScript---ECMA对象
1.对象的概念及分类 1.1 ECMAScript中没有类,但定义了“对象”,逻辑上等价于其他程序设计语言中的类. var o = new Object(); 1.2 本地对象(native obje ...
- 动态代理和AOP
之前说过了我对IOC的理解,这篇文章说以下我对动态代理和基本的对AOP的理解. 所谓动态代理就是,在运行时,动态创建实现了一组指定接口的实现类对象. 比如有: interface A { } inte ...
- 【CSS】多行溢出显示省略号
display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;//超出三行隐藏 overflow: hidden; ...
- POJ:3045-Cow Acrobats
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6253 Accepted: 2345 Descript ...
- [Codeforces967C]Stairs and Elevators(二分查找)
[不稳定的传送门] Sloution 每次试一下最近的2个楼梯或者电梯就行了 Code #include <cstdio> #include <algorithm> #incl ...
- 17-比赛1 C - Binary Nim (栈的游戏)
题目描述 Tweedle-Dee 和 Tweedle-Dum 正在进行一场激烈的二进制 Nim 游戏.这是你没有玩过的船新版本,游戏包含 N 个栈,每个栈只包含 0 和 1 的元素.就像一般的 Nim ...
- 存在チェックのみする場合はcount(*)でOK
SELECT SINGLE COUNT(*) FROM T001 WHERE BUKRS = P_BUKRS. IF SY-SUBRC <> 0. ENDIF.
- 20145202马超 《Java程序设计》第七周学习总结
Arrays:用于操作数组的工具类. 里面都是静态方法. asList:将数组变成list集合. 把数组变成集合的好处:可以使用集合的思想来操作数组中的元素. 将数组变成集合的时候不可以使用集合的增删 ...
- Best Practices in JavaScript
Some items you should konw : Graceful degradation : ensuring that your web pages still work without ...
- 剑指Offer - 九度1391 - 顺时针打印矩阵
剑指Offer - 九度1391 - 顺时针打印矩阵2013-11-24 04:55 题目描述: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 ...