题目链接:

https://cn.vjudge.net/problem/POJ-1740

题目描述:

Alice and Bob decide to play a new stone game.At the beginning of the game they pick n(1<=n<=10) piles of stones in a line. Alice and Bob move the stones in turn.
At each step of the game,the player choose a pile,remove at
least one stones,then freely move stones from this pile to any other
pile that still has stones.

For example:n=4 and the piles have (3,1,4,2) stones.If the
player chose the first pile and remove one.Then it can reach the follow
states.

2 1 4 2

1 2 4 2(move one stone to Pile 2)

1 1 5 2(move one stone to Pile 3)

1 1 4 3(move one stone to Pile 4)

0 2 5 2(move one stone to Pile 2 and another one to Pile 3)

0 2 4 3(move one stone to Pile 2 and another one to Pile 4)

0 1 5 3(move one stone to Pile 3 and another one to Pile 4)

0 3 4 2(move two stones to Pile 2)

0 1 6 2(move two stones to Pile 3)

0 1 4 4(move two stones to Pile 4)

Alice always moves first. Suppose that both Alice and Bob do their best in the game.

You are to write a program to determine who will finally win the game.

Input

The input contains several test cases. The first line of each
test case contains an integer number n, denoting the number of piles.
The following n integers describe the number of stones in each pile at
the beginning of the game, you may assume the number of stones in each
pile will not exceed 100.

The last test case is followed by one zero.

Output

For each test case, if Alice win the game,output 1,otherwise output 0.

Sample Input

3
2 1 3
2
1 1
0

Sample Output

1
0
 /*
题意描述
有n堆石子,每堆石子有pi个,两人轮流操作,每人每次选择一堆,至少移除一个,至多取完这一堆,然后移动该堆剩下的石子到其他任意堆
(只要该堆还有石子),最后一个取完石子者胜,问都采取最优策略最后谁赢。
构造博弈
先来看看一般规律
有一堆,先手必胜(直接取完)
有两堆,若两堆数目相同,为奇异局势,后手只需采取和先手相同的策略,再次构造奇异局势,最后先手必败。
若两堆数目不同,为非奇异局势,先手构造奇异局势,造成后手必败。
有三堆,先手设法构造奇异局势,先选择一堆,移除一定数目的石子,剩下的补充到其他堆,造成对手面对奇异局势,从而必胜。
有四堆,分成两个两堆,如果至少存在一对数目不同,先手构造奇异局势,可造成后手必败(回到有两堆的情况),否则,也就是都能凑成奇
异局势,而先手面临的全是奇异局势,则必败。
可以发现,当有奇数堆的时候,先手总是有机会选取一堆石子,构造至少一个奇异局势,从而必胜。
具体实现
奇数堆,先手必胜
偶数堆,至少存在一个非奇异局势,先手必胜,否则必败。
*/
#include<cstdio>
#include<algorithm>
using namespace std; const int maxn=+;
int main()
{
int n,p[maxn];
while(scanf("%d",&n) == && n != ){
for(int i=;i<n;i++)
scanf("%d",&p[i]); if(n & )
puts("");
else{
sort(p,p+n);
int i;
for(i=;i < n; i+=){
if(p[i] != p[i-]){
puts("");
break;
}
} if(i == n+)
puts("");
}
}
return ;
}

 

POJ 1740(构造博弈)的更多相关文章

  1. POJ 1740 A New Stone Game(博弈)题解

    题意:有n个石子堆,每一个都可以轮流做如下操作:选一个石堆,移除至少1个石子,然后可以把这堆石子随便拿几次,随便放到任意的其他石子数不为0的石子堆,也可以不拿.不能操作败. 思路:我们先来证明,如果某 ...

  2. POJ 1740 A New Stone Game 又是博弈论配对找规律orz 博弈论 规律

    http://poj.org/problem?id=1740 这个博弈一眼看上去很厉害很高大上让人情不自禁觉得自己不会写,结果又是找规律…… 博弈一般后手胜都比较麻烦,但是主要就是找和先手的对应关系, ...

  3. poj 2425 AChessGame(博弈)

    A Chess Game Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3791   Accepted: 1549 Desc ...

  4. poj 1740 A New Stone Game(博弈)

    A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5338   Accepted: 2926 ...

  5. POJ 1740 A New Stone Game(普通博弈)

    A New Stone Game 题意: 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆.最后谁无子可取即输 ...

  6. POJ 1740 A New Stone Game(多堆博弈找规律)

    传送门 //有n堆,AB轮流从n堆的一堆中移任意个,可以扔掉,也可以移给其他堆中的一堆 //最先移完的胜 //如果n堆中两两堆数目相等,那肯定是B胜 //但只要有非两两相同的,如xyz,A先, //A ...

  7. poj 1704 阶梯博弈

    转自http://blog.sina.com.cn/s/blog_63e4cf2f0100tq4i.html 今天在POJ做了一道博弈题..进而了解到了阶梯博弈...下面阐述一下我对于阶梯博弈的理解. ...

  8. POJ 1740 A New Stone Game

    A New Stone Game Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5453   Accepted: 2989 ...

  9. POJ 2960 S-Nim<博弈>

    链接:http://poj.org/problem?id=2960 #include<stdio.h> #include<string.h> ; ; int SG[N];//S ...

随机推荐

  1. js-倒计时原理

    <!DOCTYPE html><html>    <head>        <meta charset="UTF-8">      ...

  2. js反选

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  3. AutoCompleteTextView 简单用法

    http://blog.csdn.net/i_lovefish/article/details/17337999

  4. debian7(wheezy)升级安装mercurial hg最新版2.8-RC,解决tortoisehg2.9.2不能使用。

    debian&(wheezy)之前的仓库版本是2.2.2.  注: 本文以 # 为开始的行是工作在root下的模式,在终端显示为root的提示符# ,用户目录的($:)需要切换到root(使用 ...

  5. iOS处理视图上同时添加单击与双击手势的冲突问题

    _bgView.userInteractionEnabled = YES; //在cell上添加 bgView,给bgView添加两个手势检测方法 UITapGestureRecognizer *do ...

  6. Python自动化开发 - 字符串, 列表, 元组, 字典和和文件操作

    一.字符串 特性:字符串本身不可修改,除非字符串变量重新赋值.Python3中所有字符串都是Unicode字符串,支持中文. >>> name  = "Jonathan&q ...

  7. cxgrid动态多表头

    function TForm15.CreateBand(View: TcxGridDBBandedTableView;  BandCaption, ParentBandCaption: String) ...

  8. Windows安装配置docker

    如果是win10的,请在https://docs.docker.com/docker-for-windows/install/#download-docker-for-windows 下载Stable ...

  9. MySQL1安装

    ---恢复内容开始--- (1)安装MySQL ①ZIP安装 ②MSI安装(Windows Installer) Ⅰ  先从官网下载 目前选择使用Typical安装↑ 目前不勾选配置选项↑ 找到配置向 ...

  10. C#6.0语言规范(八) 语句

    C#提供了各种语句.大多数这些语句对于使用C和C ++编程的开发人员来说都很熟悉. statement : labeled_statement | declaration_statement | em ...