题目链接:

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 ;
}

 

最新文章

  1. EF架构~EF异步改造之路~让DbContextRepository去实现异步接口
  2. 0027 Java学习笔记-面向对象-(非静态、静态、局部、匿名)内部类
  3. IntelliJ idea的使用
  4. 基于Retrofit+RxJava的Android分层网络请求框架
  5. c# 多语言实现 与 InitializeCulture
  6. 《APUE》第6章笔记
  7. Android 解析 xml
  8. G - Bullseye
  9. jquery validation plugin 使用
  10. StarTeam SDK 13 下载安装
  11. MemCache分布式内存对象缓存系统
  12. JAVA NIO学习二:通道(Channel)与缓冲区(Buffer)
  13. Javasript设计模式之链式调用
  14. 15.linux基础
  15. 使用pm2在同服务器配置开发、生产、测试等环境
  16. SQL注入之重新认识
  17. [学习笔记]Javascript采用二进制浮点数和四舍五入的错误
  18. 升级安装APK兼容Android7.0,解决FileUriExposedException
  19. typescript接口的概念 以及属性类型接口
  20. linux命令学习之:sort

热门文章

  1. python 引入本地module
  2. centos下添加epel源
  3. 2.虚拟机安装的ubuntu全屏显示
  4. [转载]WIKI MVC模式
  5. 经过实际验证的C#调用Haskell的方法
  6. ZJOI Round2游记
  7. [NOI2018]你的名字(后缀自动机+线段树合并)
  8. [JavaScript] iframe更改了src后,父页面history.back只能后退iframe而不能使自己后退解决办法
  9. 对drf的初步认识
  10. 【Spark调优】:RDD持久化策略