POJ 1740 A New Stone Game
发布日期:2021-07-27 13:45:05 浏览次数:1 分类:技术文章

本文共 2485 字,大约阅读时间需要 8 分钟。

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

题意:

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

最后谁无子可取即输。

分析:

首先看两堆:1 1 的状态肯定是先手输~~但是俩数不一样的话就是先手赢了。。

再看三堆:1 1 1的状态肯定是先手赢,1 2 1也是先手赢。。。1 2 2也是先手赢。。总之都是先手赢。。

再看四堆:1 1 2 2 这样的肯定是先手输。。1 1 2 3 这样的就是先手赢了。。。1 2 3 4是先手赢。。

再看五堆:1 1 1 1 1 是先手赢。。1 1 1 1 2 先手赢。。。。…………都是先手赢。。1 2 3 4 1 也是先手赢。。。。各种先手赢。。

由上我们可以得出结论。。。堆的个数为奇数的情况下。。各种先手赢。总是先手赢。。。堆的数目为偶数的情况下。。如果当前各个堆的石头数目能够对称。。也就是说。。把石头数目排序之后。。第1、2堆数量相等。。3、4堆数量相等,5、6堆数量相等………………这样的情况下。。先手必输。。其他情况都是先手赢。。。

一开始,将i+=2写成了i++,各种wa。。。

#include
#include
#include
using namespace std;int n,a[11];int main(){ while(scanf("%d",&n)&&n) { int tot=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]); if(n%2==1) { printf("1\n"); continue; } sort(a+1,a+n+1); for(int i=2;i<=n;i+=2) if(a[i]==a[i-1]) tot++; if(tot==n/2) printf("0\n"); else printf("1\n"); } return 0;}

转载地址:https://blog.csdn.net/Rlt1296/article/details/51878162 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:BZOJ 1115: [POI2009]石子游戏Kam
下一篇:洛谷 P1082 同余方程

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月27日 14时49分12秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章