Hdoj 2509 Be the Winner
For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is
the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).
Input
You will be given several cases. Each test case begins with a single number n (1 <= n <= 100), followed by a line with n numbers, the number of apples in each pile. There is a blank line between cases.
Output
If a winning strategies can be found, print a single line with "Yes", otherwise print "No".
Sample Input
2
2 2
1
3
Sample Output
No
Yes anti_nim游戏。
这种Nim是不能操作者赢。
Sg函数的话还是和普通的Nim一样,初始化是sg[0]=0;
最后游戏的和的话,先手必胜当且仅当:
1.每一堆石子都是1并且Nim和为0.
2.有至少一堆石子>1并且Nim和不为0.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int sg[105],n,m;
int now,v[1005]; inline void init(){
sg[0]=0;
for(int i=1;i<=100;i++){
now=0;
for(int j=0;j<i;j++)
for(int k=j;k+j<i;k++) v[sg[j]^sg[k]]=i;
while(v[now]==i) now++; sg[i]=now;
}
} int main(){
init(); while(scanf("%d",&n)==1){
bool flag=0;
int a,ans=0; while(n--){
scanf("%d",&a);
ans^=sg[a];
if(a>1) flag=1;
} if((!flag&&!ans)||(flag&&ans)) puts("Yes");
else puts("No");
} return 0;
}
Hdoj 2509 Be the Winner的更多相关文章
- HDU 2509 Be the Winner nim博弈变形
Be the Winner Problem Description Let's consider m apples divided into n groups. Each group contai ...
- hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)
Problem Description Little John is playing very funny game with his younger brother. There is one bi ...
- hdu 2509 Be the Winner(anti nim)
Be the Winner Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 2509 Be the Winner 博弈论
博弈论水题!!! 代码如下: #include<stdio.h> #include<iostream> using namespace std; int main(){ int ...
- hdu 2509 Be the Winner 博弈
题目链接 有n堆苹果, 对于其中的每一堆的x个苹果, 它是放在一条线上的. 你每次可以对一堆苹果进行操作, 可以取y个, 1<=y<=x. 然后如果你是取的一条线上中间的苹果, 那么这一堆 ...
- (step8.2.2)hdu 2509(Be the Winner——简单博弈)
题目大意:输入一个整数n,表示火柴堆数(原题其实指的是苹果堆数,但是为了尽量与模板保持一致,所以在这里理解为火柴堆数....其实理解为什么都没关系, 重要的是,理解就行....).在接下来的一行中,有 ...
- HDU 2509 Be the Winner(取火柴博弈2)
传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...
- HDU-2509 Be the Winner
http://acm.hdu.edu.cn/showproblem.php?pid=2509 Be the Winner Time Limit: 2000/1000 MS (Java/Others) ...
- Be the Winner HDU - 2509(反博弈。。这样叫应该没错吧。。)
就是 好几堆苹果 每堆苹果排成一条线 可以任意从每堆拿苹果 如果一堆苹果里拿了之后 则有两种情况 1.从不是边缘拿 拿完这一堆变成两堆 2.从边缘拿 拿完还是一堆 题目还要求 谁 ...
随机推荐
- Android Shader渲染器:BitmapShader图片渲染
public class BitmapShader extends Shader BitmapShader, Shader家族的 专门处理图片渲染的 构造方法: public BitmapShade ...
- P3398 仓鼠找sugar(树链剖分)
P3398 仓鼠找sugar 题目描述 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐厅(b),而 ...
- Redis实现之事件
事件 Redis服务器是一个事件驱动程序,服务器需要处理以下两类事情: 文件事件(file event):Redis服务器通过套接字与客户端(或者其他Redis服务器)进行连接,而文件事件就是服务器对 ...
- 使用code::blocks编译windows的dll链接库
因为机子上没有安装Visual Studio,所以找到了一种通过code::blocks编译dll的方式,踩到的坑是code::blocks默认的compiler是32位的,这样编译出的dll也是32 ...
- IOS开发学习笔记035-UIScrollView-自动滚动
让图片自动滚动的话,需要使使用定时器,循环计算当前页的页码.并且在拖动图片时停止计时器,停止拖动时启动计时器. 定时器 方法1: performSelector [self performSelect ...
- IOS开发学习笔记022-imageView实现动画
这里要播放的动画是很多张连续的动画,连续播放就会显示出动画效果. 大概过程是: 新建一个single view application ,然后添加一个image View控件到视图.给image vi ...
- Xmanager用法(export DISPLAY=客户端IP:0.0)
1.在用户的目录下找到文件.bash_profile或profile,用vi对其进行编辑.加入下列命令行: DISPLAY=192.168.88.71:0.0;export DISPLAY 2.如果只 ...
- sqlserver 获取一个月有多少天
--思路:给定日期的下一个月的1号减去1天,然后取datepart(DAY,dt) declare @dt varchar(10)select @dt='2013-11-20'select datep ...
- ftp下出现“当前的安全设置不允许从该位置下载文件”提示
在资源管理器中使用ftp协议下载文件时,提示“当前的安全设置不允许从该位置下载文件”,下载失败. 解决方法: 1.在自己的电脑上打开Internet选项
- 【bzoj2186】[Sdoi2008]沙拉公主的困惑 欧拉函数
题目描述 大富翁国因为通货膨胀,以及假钞泛滥,政府决定推出一项新的政策:现有钞票编号范围为1到N的阶乘,但是,政府只发行编号与M!互质的钞票.房地产第一大户沙拉公主决定预测一下大富翁国现在所有真钞票的 ...