题目链接:

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. Ubuntu12.04搭建自有源

    其实,这个工作比较简单,主要两步:apt-mirror和apache.(这里的系统是ubuntu12.04) 1.apt-mirror 1.1 安装 一如既往地简单,直接sudo apt-get in ...

  2. allegro中如何添加安装孔(注:在PCB图纸中添加)

    最近再给外国一家公司做某一个小的系统模块的封装,其中这个模块中间是挖空的,这就比较难办,到现在为止我还没有找到如何在封装中添加自己绘制特定形状的过孔,(倒是可以添加软件自带的一些圆形的安装孔)最终解决 ...

  3. [ASE][Daily Scrum]11.06

    我们的<坦克大战·无尽>正式开始动工了,今天的任务计划如下~ [Plan] View Shilin Liu 搭建好开发环境 收集素材         Control Jiafan Zhu ...

  4. Martin Fowler 分层测试概念博文分享

    在我们测试工作中,常常遇到这样的问题:开发与测试团队分属不同的不同(部门隔离.沟通不畅),质量职责划分不清(出现bug往往都是测试人员背锅),需求的不确定和易变性(需求不断变化导致代码不停更新.产品重 ...

  5. 轻量级Config文件AppSettings节点编辑帮助类

    using System.Configuration; using System.Windows.Forms; namespace Allyn.Common { public class XmlHep ...

  6. 第二节:创建模型,使用Code First,配置映射关系

    这一节,实现模型的创建,配置映射关系 使用Code First数据迁移. 创建模型 一,首先创建几个接口:实体接口,聚合根接口,值对象接口 1,实体接口: 2,聚合根接口: 3,值对象接口: 二,模型 ...

  7. nodejs 环境配置技巧

    环境:Mac OSX 10.10.3 NodeJS:v0.12.2 NodeJs 安装指需要 1.执行 npm install xxxx -g 时 需要执行 sudo npm install xxxx ...

  8. Java内存模型与共享变量可见性

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 注:本文主要参考自<深入理解Java虚拟机(第二版)>和<深入理解Java内存模型> ...

  9. 【BZOJ2328】 [HNOI2011]赛车游戏

    BZOJ2328 [HNOI2011]赛车游戏 前言 这道题目我真的佛了,卡精度+卡时间这就是下一个聊天鬼才. Solution 首先可以二分出最大速度,然后考虑下坡的话可能有更好的解,然后这样子算一 ...

  10. 【友情链接】各位dalao的博客

    同省神犇 HA队长 __stdcall HA chty_syq为文文讲过字符串 HA cdcq为文文讲过后缀数组① ② Bluesky007超强的 外省神犇 知名OIer黄学长 一个可爱的蓝孩子qwq ...