Be the Winner

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4939    Accepted Submission(s): 2724

Problem Description
Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged in a line. You can take any number of consecutive apples at one time.
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

题意:有n堆苹果,每堆有数个。两个人轮流取,每次至少取一个,取走最后一个的算输。

题解:是反nim博弈。先手必胜的两个结论:(1)每堆苹果都只有一个,而且有偶数堆(异或和为0),那么先手必胜。(2)至少有一堆苹果中个数超过一个,那么异或和不为0,先手必胜。

https://www.cnblogs.com/SilverNebula/p/5658629.html      顶

 #include<bits/stdc++.h>
using namespace std;
int main() {
int n;
while(~scanf("%d",&n))
{
int ans=,ai,num=;
for(int i=;i<n;i++)
{
scanf("%d",&ai);
ans^=ai;
if(ai>)num=;
}
if(num)
{
if(ans==)printf("No\n");
else printf("Yes\n");
}
else
{
if(ans==)printf("Yes\n");
else printf("No\n");
}
}
return ;
}

hdu2509Be the Winner(反nim博弈)的更多相关文章

  1. hdu1907John(反nim博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  2. LightOJ 1253 Misere NIM(反NIM博弈)

    Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, eac ...

  3. 反Nim博弈

    原文地址:https://blog.csdn.net/xuejye/article/details/78975900 在尼姆博奕中取完最后一颗糖的人为赢家,而取到最后一颗糖为输家的就是反尼姆博奕.这道 ...

  4. 博弈论中的Nim博弈

    瞎扯 \(orzorz\) \(cdx\) 聚聚给我们讲了博弈论.我要没学上了,祝各位新年快乐.现在让我讲课我都不知道讲什么,我会的东西大家都会,太菜了太菜了. 马上就要回去上文化课了,今明还是收下尾 ...

  5. 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 ...

  6. HDU 5754 Life Winner Bo 组合博弈

    Life Winner Bo Problem Description   Bo is a "Life Winner".He likes playing chessboard gam ...

  7. POJ 2234 Matches Game(Nim博弈裸题)

    Description Here is a simple game. In this game, there are several piles of matches and two players. ...

  8. POJ2234:Matches Game(Nim博弈)

    Matches Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12325   Accepted: 7184 题目链 ...

  9. hdu 1907(Nim博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

随机推荐

  1. WMIC_2

  2. 2019.1.9 Mac安装Iterm2 终端(oh my zsh的安装与配置)

    Mac安装Iterm2 终端(oh my zsh的安装与配置) 安装 curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tool ...

  3. maven 打包时动态替换properties资源文件中的配置值

    pom build节点下面添加resource配置: <resources> <resource> <directory>src/main/resources/&l ...

  4. ON_COMMAND ON_MESSAGE ON_NOTIFY区别与联系

    ON_COMMAND是菜单和工具栏项处理消息的宏 ON_MESSAGE是处理自定义消息的宏 ON_NOTIFY 是控件向其父窗口发送消息处理的宏 对这几个消息的理解要先了解一下Window消息的背景. ...

  5. mongodb安装(比较全一点)

    Linux下MongoDB安装和配置详解  转:https://www.cnblogs.com/pfnie/articles/6759105.html 一.创建MongoDB的安装路径 在/usr/l ...

  6. ORM优缺点

    优点: 1.提高了开发效率.由于ORM可以自动对Entity对象与数据库中的Table进行字段与属性的映射,所以我们实际可能已经不需要一个专用的.庞大的数据访问层. 2.ORM提供了对数据库的映射,不 ...

  7. ARM 汇编指令集 特点之一:指令后缀

    1.同一 指令 添加不同的后缀 就会有不同的功能! 例子: B (Byte)  功能不变,操作长度变为8位 H (Half Word) 功能不变,操作长度变为16位 S(Signed) 功能不变,操作 ...

  8. 数据库——MySQL——索引——索引原理及B+树

    索引原理 我们使用索引,就是为了提高查询的效率,如同查书一样,先找到章,再找到章中对于的小节,再找到具体的页码,再到我们需要的内容. 事实上索引的本质就是不断缩小获取数据的筛选范围,找出我们想要的结果 ...

  9. 轻量ORM-SqlRepoEx (八)MySQL、Sql Service 迁移

    数据库变更在编程应用中是常的,MySQL.Sql Service之间的数据迁移更为常见,在 SqlRepoEx2.0DemoForAspCore中演示了,这种数据库之间切换时SqlRepoEx是如何的 ...

  10. 搭建Extjs框架(二)

    搭建Extjs 框架 二.编写入口文件 app.js,配置extjs 组件\视图文件路径 并将app.js引入index.html       在app.js中指定一些文件的路径,Extjs页面的起始 ...