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

Description

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

Source

分析引自: http://www.cnblogs.com/rainydays/archive/2011/07/09/2101918.html

题意:对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆。

最后谁无子可取即输。

分析:首先我们考虑两堆相等的情况,一定是谁取谁输,因为对方永远可以做对称的操作。对于四堆,1、2堆相等,3、4堆相等的情况,一定也是先手输,后手也只需要做对称的操作(在先手取石子的对称堆中取相同多的石子,并把和先手等量的石子分给先手分配给的堆的对称堆。(若先手在3堆取,并分给1堆,那后手就在4堆取,分给2堆)。也就是说对于任意的一对一对相等的情况来说,一定是后手必胜。

我们接下来来证明除上述情况外,所有情况都是先手必胜。因为任何一种情况都可以转化为一对一对相等的情况。若总堆数为奇数的情况,可以把石子最多的一堆的石子分配给其它堆,使得其它堆两两相等。最多一堆的石子绝对是足够多,可以完成这个补齐的任务的。因为我们把石子从小到大排序后画成条形统计图。把相邻两个分成一组(1和2一组,3和4一组……)我们需要用第n堆填补1,3,5……堆我们把需要填补的这些差距(2比1高出的部分,4比3高出的部分……)投影到统计图左侧的y轴上,我们会发现这是一些不连续的区间,其长度总和明显小于第n堆。所以可以补齐。

对于堆数为偶数的情况。我们把最多的一堆削弱到和最少的一堆一样多,并把拿掉的石子分给别的堆,使其一对一对地相等。可行性于前面奇数情况同理。

所以只要判断是不是一对一对的相等的情况即可。

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
bool f[];
int cnt;
int num;
int n;
int main(){
while(scanf("%d",&n) && n){
memset(f,false,sizeof f);
cnt=;
for(int i=;i<=n;i++){
scanf("%d",&num);
if(f[num])cnt--;
else cnt++;
f[num]=!f[num];//状态取反
}
if(cnt) printf("1\n");
else printf("0\n");
}
return ;
}

POJ 1740 A New Stone Game的更多相关文章

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

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

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

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

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

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

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

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

  5. 博弈论(男人八题):POJ 1740 A New Stone Game

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

  6. [原博客] POJ 1740 A New Stone Game

    题目链接题意:有n堆石子,两人轮流操作,每次每个人可以从一堆中拿走若干个扔掉(必须),并且可以从中拿走一些分到别的有石子的堆里(可选),当一个人不能拿时这个人输.给定状态,问是否先手必胜. 我们参考普 ...

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

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

  8. POJ 1740:A New Stone Game

    A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5113 Accepted: 2806 Desc ...

  9. 【POJ 1740】A New Stone Game

    这真是一道博弈论的好题啊 还是采用OI届的惯用套路,从简单想起 如果只有一堆石子,那么一定先手必胜 如果有两堆石子,那么我们考虑如下两种情况 2.1 两堆石子数量相同,那么无论先手怎么拿,后手都有一种 ...

随机推荐

  1. Android开发EditText属性

    Android开发EditText属性 EditText继承关系:View-->TextView-->EditText EditText的属性很多,这里介绍几个:android:hint= ...

  2. zepto.js 源码解析

    http://www.runoob.com/w3cnote/zepto-js-source-analysis.html Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jqu ...

  3. onresize方法

    resize()方法可以写在当前页面包含的所有js里

  4. 20Mybatis_订单商品数据模型_一对一查询——resultType和resultMap两种方式以及两种方式的总结

    上一篇文章分析了数据模型,这篇文章就给出一个需求,这个需求是一对一查询,并完成这个需求. ------------------------------------------------------- ...

  5. 【WPF】WPF中调用Winform

    1.添加两个引用:WindowsFormsIntegration.dll(负责整合WPF和Windows).System.Windows.Forms.2.在 XAML文件中添加两个引用(粗体部分): ...

  6. pc加入域认证细节

    计算机组织形式 工作组(无法统一管理,无法统一身份验证) 域 win权限分配机制 管理本地用户 新建用户-加入管理员组. 针对文件夹基于(用户组)设置权限 用户SID 创建一个用户时候,每个用户都有一 ...

  7. 基于Flot可放缩的折线图

    Flot初步 Flot是一个免费开源的图标插件,可以用它开发出功能强大的图表系统.下面着重讲解在Asp.net中如何使用这个插件做出功能强大的图表应用. 关于Flot,可以在这里查看现有的例子(或者是 ...

  8. 20145222黄亚奇《Java程序设计》第1周学习总结

    教材学习内容总结 BJVM是Java程序唯一认识的操作系统,其可执行文件为.class文档 Java的三大平台为Java SE,Java EE,Java ME. Java SE的四个部分为:JVM,J ...

  9. windows2003 单网卡 搭建vpn ,windows 2008 R2 类似吧。网上转的,自己加了点经验总结

    先说说可能的坑,也就是我自己搭建的时候碰到的问题. 其实搭建起来很简单,我不知道我总结的对还是不对,但是按下面这样操作做绝对能搭好!因为我就是按这样搭起来的,但是我发现,好像pptp已经被墙了,我也不 ...

  10. 开始学习node.js了,第一节,fs文件系统 【fs.rename】重命名文件/文件夹

    var fs=require('fs');fs.rename('c:\\a','c:\\a2',function(err){ if(err) console.log('error:'+err);}); ...