题目链接:

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. day02_雷神_字符串、列表、字典

    1.字符串 1.1 字符串相加 s1 = " ale x " s2 = " sb " print(s1 + s2) #识别空格 print(s1.strip() ...

  2. 电容器的ESR

    电容器的ESR(等效串联电阻)Equivalent Series Resistance    作为开关电源的输出整流滤波电容器,电容量往往是首要的选择,铝电解电容器的电容量完全可以满足要求,而ESR则 ...

  3. Oracle包被锁定的原因分析及解决方案

    http://blog.csdn.net/jojo52013145/article/details/7470812 在数据库的开发过程中,经常碰到包.存储过程.函数无法编译或编译时会导致PL/SQL ...

  4. Spring @Autowired注解用在集合上面,可以保持接口的所有实现类

    CourseService课程接口有2个子类,HistroyCourseServiceImpl和MathsCourseServiceImpl public interface CourseServic ...

  5. Redis 5.0 安装

    下载安装RedisServer mkdir –p /data/download && cd /data/download wget http://download.redis.io/r ...

  6. Git项目下载部分文件或文件夹

    我们常常要在Github下载一些源码.示例等,但有时候项目库会比较大,而我关心的只是其中很少的一部分内容,由于众所周知的原因,我们下载git库是比较慢的,过大的项目经常会下载失败,所以只下载部分内容就 ...

  7. .net core中Quartz的使用

    原来工作中有用到定时任务Quartz,不过是在MVC项目中,现在net core项目中也要用到,就开始改版.中间发现在网上的教程只有执行定时计划的过程,却很少有人写注册的过程,觉得有点略坑.所以写此文 ...

  8. System.Data.SQLite安装的相关问题

    在使用System.Data.SQLite的过程中,遇到各种问题,特此记录下.(都被搞的折寿了,不仔细看文档的下场!) 1.选对.net Framework的版本. 2.X64和X86的问题,如果项目 ...

  9. linux服务器的相关信息查看(端口占用,cpu、内存占用,防火墙,系统信息,vim编辑器使用等)

    一.端口占用情况   https://www.cnblogs.com/CEO-H/p/7794306.html (1)查看所有端口.进程的使用情况:netstat -tunlp (2)查看某一端口的使 ...

  10. flask_json数据入库Mongo

    首先我们先导入python内置的json库,用来将接送数据转换为python对象 import json #导入自定义的数据公共库 from db_tool import db #载入库之前先清空数据 ...