POJ 1704 (Georgia and Bob-Nim game)

Source: Internet
Author: User

Georgia and Bob
Time Limit: 1000 MS Memory Limit: 10000 K
Total Submissions: 6341 Accepted: 1826

Description

Georgia and Bob decide to play a self-defined Ted game. they draw a row of grids on paper, number the grids from left to right by 1, 2, 3 ,..., and place N chessmen on different grids, as shown in the following figure for example:

 


 

Georgia and Bob move the chessmen in turn. every time a player will choose a chessman, and move it to the left without going over any other chessmen or keep ss the left edge. the player can freely choose number of steps the chessman moves, with the constraint that the chessman must be moved at least ONE step and one grid can at most contains ONE single chessman. the player who cannot make a move loses the game.

Georgia always plays first since "Lady first ". suppose that Georgia and Bob both do their best in the game, I. e ., if one of them knows a way to win the game, he or she will be able to carry it out.

Given the initial positions of the n chessmen, can you predict who will finally win the game?

Input

The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. then T cases follow. each test case contains two lines. the first line consists of one integer N (1 <= N <= 1000), indicating the number of chessmen. the second line contains N different integers P1, P2... pn (1 <= Pi <= 10000), which are the initial positions of the n chessmen.
Output

For each test case, prints a single line, "Georgia will win", if Georgia will win the game; "Bob will win", if Bob will win the game; otherwise 'Not sure '.
Sample Input

2
3
1 2 3
8
1 5 6 7 9 12 14 17
Sample Output

Bob will win
Georgia will win
Source

POJ Monthly -- 2004.07.18


First, the number is paired (a, B). If the number is an odd number, the leftmost is paired with 0.

So if we move a to the right, we also move B to the same number of steps.

The only difference is the interval between pairs.

Suppose there is an interval of c1, c2..cn

This is equivalent to selecting a number each time, minus at least 1.

This is like nim stone removal, there are n piles of stones, each time at least one pile of at least one of them is taken away, who first won't get the stones to lose.

The answer to this question is "c1 ^ c2 ^ .. ^ cn = 0". Otherwise, it will win.

All know ......

Proof:

Suppose you are facing a situation where c1 ^ c2 ^... ^ cn = 0.

A: Take away several stones so that c1 ^ c2 ^... ^ cn = k

B: The heap ci with the same highest bit of the ci and k ^ k // The 1 ^ 1 = 0 of the highest bit, so ci ^ k <ci

A: Congratulations, you still have to lose.


[Cpp]
# Include <cstdio>
# Include <cstring>
# Include <cstdlib>
# Include <algorithm>
# Include <functional>
# Include <iostream>
# Include <cmath>
# Include <cctype>
# Include <ctime>
Using namespace std;
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define Fork (I, k, n) for (int I = k; I <= n; I ++)
# Define Rep (I, n) for (int I = 0; I <n; I ++)
# Define ForD (I, n) for (int I = n; I --)
# Define RepD (I, n) for (int I = n; I> = 0; I --)
# Define Forp (x) for (int p = pre [x]; p = next [p])
Int T, n, a [100000 + 10];
Int main ()
{
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n );
For (I, n) scanf ("% d", & a [I]);
Sort (a + 1, a + 1 + n );
Int tmp = 0, head = 1;
If (n % 2) tmp = a [1]-1, head ++;
For (int I = head; I <= n; I + = 2)
{
Tmp ^ = (a [I + 1]-a [I]-1 );
}
If (tmp) puts ("Georgia will win ");
Else puts ("Bob will win ");
}
Return 0;
}

# Include <cstdio>
# Include <cstring>
# Include <cstdlib>
# Include <algorithm>
# Include <functional>
# Include <iostream>
# Include <cmath>
# Include <cctype>
# Include <ctime>
Using namespace std;
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define Fork (I, k, n) for (int I = k; I <= n; I ++)
# Define Rep (I, n) for (int I = 0; I <n; I ++)
# Define ForD (I, n) for (int I = n; I --)
# Define RepD (I, n) for (int I = n; I> = 0; I --)
# Define Forp (x) for (int p = pre [x]; p = next [p])
Int T, n, a [100000 + 10];
Int main ()
{
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n );
For (I, n) scanf ("% d", & a [I]);
Sort (a + 1, a + 1 + n );
Int tmp = 0, head = 1;
If (n % 2) tmp = a [1]-1, head ++;
For (int I = head; I <= n; I + = 2)
{
Tmp ^ = (a [I + 1]-a [I]-1 );
}
If (tmp) puts ("Georgia will win ");
Else puts ("Bob will win ");
}
Return 0;
}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.