poj 1740 A New Stone Game(博弈)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 5338 | Accepted: 2926 |
Description
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
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
Sample Input
3
2 1 3
2
1 1
0
Sample Output
1
0
Source
【思路】
博弈
当n=1时,先手必胜;
当n=2时,如果两堆相等,先手取后只剩一堆则局面必胜,先手取后剩两堆,则后手可以始终维持两堆相等直到(1,1),此时必由先手完成第一种情况。因此先手必败。
当n=3时,若a1<=a2<=a3,则先手可以通过操纵a3使得剩下两堆为(a2,a2),此时局面必败。因此先手必胜。
推广:
当n为奇数时,若a1<=a2…<=an-1<=an,则操作an使得a1->a2,a3->a4….an-2->an-1,因为项为正,所以an>=a2-a1+…an-1-an-2。因此先手必胜。
当n为偶数时:若a1=a2,a3=a4…an-2=an-1,则先手必败;否则总可以操作an使得an=a1,a2=a3…an-2=an-1,an-a1>=a2-a2+…an-1-an-2,此时先手必胜。
【代码】
#include<cstdio>
#include<algorithm>
using namespace std; int n,a[]; int main() {
while(scanf("%d",&n)== && n) {
for(int i=;i<=n;i++) scanf("%d",&a[i]);
if(n&) puts("");
else {
sort(a+,a+n+);
int flag=;
for(int i=;i<=n;i+=)
if(a[i]!=a[i+]) { flag=; break; }
if(flag) puts(""); else puts("");
}
}
return ;
}
poj 1740 A New Stone Game(博弈)的更多相关文章
- POJ 1740 A New Stone Game(博弈)题解
题意:有n个石子堆,每一个都可以轮流做如下操作:选一个石堆,移除至少1个石子,然后可以把这堆石子随便拿几次,随便放到任意的其他石子数不为0的石子堆,也可以不拿.不能操作败. 思路:我们先来证明,如果某 ...
- POJ 1740 A New Stone Game(普通博弈)
A New Stone Game 题意: 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆.最后谁无子可取即输 ...
- POJ 1740 A New Stone Game(多堆博弈找规律)
传送门 //有n堆,AB轮流从n堆的一堆中移任意个,可以扔掉,也可以移给其他堆中的一堆 //最先移完的胜 //如果n堆中两两堆数目相等,那肯定是B胜 //但只要有非两两相同的,如xyz,A先, //A ...
- POJ 1740 A New Stone Game 又是博弈论配对找规律orz 博弈论 规律
http://poj.org/problem?id=1740 这个博弈一眼看上去很厉害很高大上让人情不自禁觉得自己不会写,结果又是找规律…… 博弈一般后手胜都比较麻烦,但是主要就是找和先手的对应关系, ...
- POJ 1740 A New Stone Game
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5453 Accepted: 2989 ...
- [原博客] POJ 1740 A New Stone Game
题目链接题意:有n堆石子,两人轮流操作,每次每个人可以从一堆中拿走若干个扔掉(必须),并且可以从中拿走一些分到别的有石子的堆里(可选),当一个人不能拿时这个人输.给定状态,问是否先手必胜. 我们参考普 ...
- 博弈论(男人八题):POJ 1740 A New Stone Game
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5694 Accepted: 3119 ...
- poj 1704 Georgia and Bob(阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9363 Accepted: 3055 D ...
- Something about 博弈(POJ 3922 A simple stone game)
先是题目,本来是第三次训练的题,在这特别提出来讲. 先是题目: E - A simple stone game Time Limit:1000MS Memory Limit:65536KB ...
随机推荐
- JSP三个指令及9个内置对象
注:本文编写方便自己以后用到时查阅 三大指令:include. page.taglib include指令: 作用: 在当前页面用于包含其他页面 语法: <%@include file=&qu ...
- [lua]尝试一种Case语法糖
function CaseT(arg) function proxy(caller) caller.yield(r) end -- proxy return function (cond) if (c ...
- CSS3—CSS3和现代Web设计
1.1 现代Web设计理念 1.1.1 可访问性第一 同样一段内容, 可以用成千上万的方法为其设计样式, 但全世界的用户应该依然可以访问它们, 不管他们用什么方式去访问Web——无论手机.键盘控制器还 ...
- js跳转页面方法
<span id="tiao">3</span><a href="javascript:countDown"></ ...
- java 整体字体样式设置
两种方式: 1.UIManager.put("Button.font", new Font("MS UI Gothic", Font.PLAIN, 24)) ...
- ab基本用法
ab的全称是ApacheBench,是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchmark testing,可以同时模拟多个并发请求.前段时间看到公司的开发人员也在 ...
- linux安装python使用的MySQLdb
安装mysqldb模块需已安装mysql 使用pip安装MySQLdb pip install mysql-python mac os安装mysqldb sudo pip install mysql- ...
- 对于volatile的理解
哎.要学的东西太多,时间太少.一周的工作下来要总结的东西太多,还处理不完,越积越多.大周末的好想出去玩啊.... 得嘞,废话止于此. 无聊时候乱看网页发现了volatile的一篇文章,以前曾经对vol ...
- linux下配置NFS服务器
(声明:本文大部分文字摘自Linux NFS服务器的安装与配置) 一.NFS简介 NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Su ...
- leetcode power(x,n)
class Solution { public: double pow(double x, int n) { double a=1; if(n==0)return 1; if(x==1)return ...