JOIN
Get Time

   Problem Statement  

 Problem Statement for MagicNim

Problem Statement

    

Alice and Bob are playing a game of Nim with n+1 piles of stones. The piles are numbered from 0 to n. For each i between 0 and n-1, inclusive, pile i contains exactly a[i] normal stones. Pile n contains exactly one magic stone.

Normal rules of Nim apply to this game: Alice and Bob take alternating turns, with Alice going first. In each turn the current player chooses a non-empty pile (between 0 and n, inclusive) and removes an arbitrary positive number of stones from the pile. The player who is unable to make a valid move loses the game. In other words, the winner is the player who removes the very last stone.

Additionally, there is a rule for the magic stone. When a player chooses pile n and removes the magic stone, they have the option to reverse the victory condition. If they choose to do so, the player who is unable to make a valid move now wins the game. If they choose not to do it, the game continues with the original victory condition.

You are given the int[] a with n elements. (Note that the pile with the magic stone is not explicitly mentioned in a.)

Help Alice and Bob determine the winner of the game, assuming both of them play optimally. Return the name of the winner: either "Alice" or "Bob".

 

Definition

    
Class:MagicNim
Method:findWinner
Parameters:int[]
Returns:String
Method signature:String findWinner(int[] a)
(be sure your method is public)
    
 

Constraints

-a will contain between 1 and 10 elements, inclusive.
-Each element of a will be between 1 and 50, inclusive.
 

Examples

0)
    
{1}
Returns: "Alice"
There are two piles. The first pile is a normal pile with one stone. The second pile contains the magic stone. In this case, Alice can take the magic stone and change the rules so that the last person who takes a stone loses. Now, Bob is forced to take the stone in the first pile, and since that is the last available stone, he loses.
1)
    
{2}
Returns: "Bob"
There are two piles. The first pile is a normal pile with two stones. The second pile contains the magic stone. In this case, no matter what Alice does, she will lose.
2)
    
{1,1,1,1}
Returns: "Alice"
3)
    
{1,1,1,1,1}
Returns: "Alice"
4)
    
{1,3}
Returns: "Bob"
5)
    
{4,4,2}
Returns: "Alice"
6)
    
{50,50,50,50,50,50,50,50,50,50}
Returns: "Alice"
7)
    
{6,7}
Returns: "Bob"

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

This problem was used for:
       Single Round Match 710 Round 1 - Division I, Level Two