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

A New Stone Game

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 5694   Accepted: 3119

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
0http://blog.csdn.net/zhang20072844/article/details/8113381这个题解很清楚。
 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cstdio>
 5 using namespace std;
 6 int a[15],f,n;
 7 int main(){
 8     while(scanf("%d",&n)!=EOF&&n){
 9         for(int i=1;i<=n;i++)
10             scanf("%d",&a[i]);
11         if(n%2==1)printf("1\n");
12         else{
13             f=0;sort(a+1,a+n+1);
14             for(int i=1;i<n;i+=2)
15                 if(a[i]!=a[i+1])f=1;
16             printf("%d\n",f);
17         }
18     }
19     return 0;
20 }
				
时间: 2024-10-21 23:20:28

博弈论(男人八题):POJ 1740 A New Stone Game的相关文章

poj 1741 楼教主男人八题之一:树分治

http://poj.org/problem?id=1741 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid

poj 1743 Musical Theme(男人八题&amp;后缀数组第一题)

Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17298   Accepted: 5939 Description A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1..88, each representing a key on the

LCT男人八题系列

楼教的男人八题名气甚大,今天做了一道感觉还是涨了不少姿势的,然而估计之后的每道题都要看题解吧,姑且先记录一下.以后再做再更 1737 Connected Graph 1100 [email protected] 1738 An old Stone Game 407 [email protected] 1739 Tony's Tour 671 [email protected] 1740 A New Stone Game 2240 [email protected] 1741 Tree 1728

POJ1742 Coins(男人八题之一)

前言 大名鼎鼎的男人八题,终于见识了... 题面 http://poj.org/problem?id=1742 分析 § 1 多重背包 这很显然是一个完全背包问题,考虑转移方程: DP[i][j]表示用前i种硬币能否取到金额j,ture表示可以,false表示不行. 则有 DP[i][j] = DP[i - 1][j] | DP[i - 1][j - k * Ai], 0 ≤ k ≤ Ci, j - k * Ai ≥ 0 这是一个O(N3)的算法,考虑到数据范围1 ≤ N ≤ 100, M ≤

男人八题2019

打的第三年男人八题了= = 感觉自己可能能创造一个EZ历史上打过最多男人八题的人(嘤嘤嘤我明明是妹子啊 考场上是5题 目前补了7题 目录 Biology Chemistry Chinese English Geography History Math Physics Biology 模拟= = //Love and Freedom. #include<cstdio> #include<algorithm> #include<cstring> #include<cm

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

题意:有n个石子堆,每一个都可以轮流做如下操作:选一个石堆,移除至少1个石子,然后可以把这堆石子随便拿几次,随便放到任意的其他石子数不为0的石子堆,也可以不拿.不能操作败. 思路:我们先来证明,如果某个石子数有偶数堆,则先手必败,因为无论先手怎么做,后手都能模仿先手,最后把石子取光.显然全是偶数堆是必败态.如果有奇数堆怎么办?我们就把最大的奇数堆取光,然后把其他奇数堆变成偶数堆.但是一定能保证可以吗?答案是可以.假设奇数堆的石子数为 x1,x2,x3...xn,那么我们分别给每一堆加上x2-x1

POJ 1741 男人八题——树分治

Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 23829   Accepted: 7900 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an

poj 1740 A New Stone Game nim变形

题意: 给n堆石子,两人交替,选择一堆石头后先拿去任意颗,再把剩下的放到其他任意堆,最先拿完所有石子赢,问先手必胜还是必败. 分析: 解决此类问题的一种的思路是先构造策略,然后判断此策略能否满足1.必胜态可到必败态.2.必败态无法到必败态. 代码: //poj 1740 //sep9 #include <iostream> #include <algorithm> using namespace std; const int maxN=128; int a[maxN]; int m

POJ 1741 Tree (树上点分治)(楼教主男人八题之一)

题目地址:POJ 1741 树分治第一发! 树分治详情请看漆子超的国家集训队论文,论文传送门 树分治裸题. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set> #