| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 594 人关注过本帖
标题:全英文的,我当场晕死。。。。
只看楼主 加入收藏
c1025329734
Rank: 1
等 级:新手上路
帖 子:50
专家分:8
注 册:2012-11-10
结帖率:69.23%
收藏
已结贴  问题点数:10 回复次数:2 
全英文的,我当场晕死。。。。
accept: 0    submit: 1

Description


Bessie has a new two-person game: TwoFour. She has N (3 <= N <= 30) piles, each with a number of balls (0 <= nballs <= 4).  The total number of balls is 2*N.

To play, the players alternate taking turns, each of which comprises a single valid move.  A valid move consists of the following actions:

  * First, the player chooses two different piles.

  * Second, she takes a single ball from one pile and moves it to the other pile. She can do this only if the number of balls in the second pile (including the new ball) is not greater than the number of balls remaining in the first pile after the ball is removed.

The game ends when no more moves can be made. In fact, at the end of the game, every pile will contain exactly two balls.

The winner of the game is the player who 'owns' most piles.  Ties are possible.  A player 'owns' a pile if the pile has two balls and this resulted from the player's most recent move to or form that pile.
Consider these examples:

    * If a player moves a ball from a pile of four balls to a pile of one ball, then she owns the second pile (with two balls).

    * If a player moves a ball from a pile of three balls to a pile of zero balls, then she owns the first pile, now with two balls.

    * If a player moves a ball from a pile of three balls to a pile of one ball, then she owns both piles (both with two balls).

Ownership can change.  Consider that a player owns a pile with twoballs. If the other chooses a pile with four balls and moves a ball to the pile with two, then the pile is no longer owned by anyone.

If, at the beginning of the game, some piles have two balls, then the piles are equally distributed among the two players with any extra pile being owned by player two.

Player 1 is the one who makes the first move.

Your program must decide, for an initial game state, who will be the winner or if the game ends in a tie when both players play as well as they can.  Your program will be presented with G (1 <= G <= 1000) game
states.
Input


* Line 1: Two space-separated integers: N and G.
* Lines 2..G+1: Each line contains N space-separated integers describing a game.  The first integer is the number of  balls in pile 1, the second integer is the number of balls in pile 2, and so on. Line 2 describes game 1, line 3 describes game 2, and so on.  Your program should compute the winner for this particular game.

Output


* Lines 1..G: The outcome of each game.  Line 1 gives the outcome of game 1, and so on.  The outcome is a single integer: 1 if the first player wins, 2 if the second player wins, and 0 if the game is a tie.
Sample Input


5 4
0 3 4 1 2
2 2 2 2 2
1 1 2 2 4
4 3 2 1 0
Sample Output


1
2
1
1
Source

USACO 2003 March

搜索更多相关主题的帖子: alternate single different following number 
2012-11-19 22:44
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:5 
需要帮你转到C语言版么
2012-11-20 08:00
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:5 
楼主是在求翻译吗
2012-11-20 14:04
快速回复:全英文的,我当场晕死。。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023080 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved