Georgia and Bob
Time Limit: 1000MS |
|
Memory Limit: 10000KB |
|
64bit IO Format: %i64d &%i64u |
Submit Status
Description
Georgia and Bob decide to play a self-invented 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 would choose a chessman, and move it to the left without going over any other chessmen or across the LE FT Edge. The player can freely choose number of steps the Chessman moves, with the constraint, the Chessman must is moved at Le AST one step and one grid can at most contains one single Chessman. The player cannot make a move loses the game.
Georgia always plays first since "Lady first". Suppose that Georgia and Bob both does their best in the game, i.e., if one of them knows a a-to-win the game, he or she w Ill is able to carry it out.
Given the initial positions of the N chessmen, can you predict who'll finally win the game?
Input
The first line of the input contains a single integer t (1 <= t <=), the number of test cases. Then T cases follow. Each test case contains the lines. The first line consists of one integer N (1 <= n <=), indicating the number of chessmen. The second line contains N different integers P1, P2 ... Pn (1 <= Pi <= 10000), which is the initial positions of the N chessmen.
Output
For each test case, prints a, "Georgia'll Win", if Georgia'll win the game; "Bob would win", if Bob would win the game; Otherwise ' not sure '.
Sample Input
231 2 381 5 6 7 9 12 14 17
Sample Output
Bob would Wingeorgia would win
First of all, see what is the ladder game. Note that this URL says "2^3^4=5 is not zero, so the initiator will be defeated" is wrong
XOR or not 0 should be the initiator win, said the reverse.
http://blog.csdn.net/kk303/article/details/6692506
Main topic: Each test point has a maximum of T (1 <= T <= 20) test data. , Georgia and Bob are playing a self-created game. An infinitely long chessboard has N flags (1 <= N <= 1000), and the position of the first piece can be represented by PI (1 <= pi <= 10000). Now Georgia go first. Each time each person can move a piece to the left of any lattice, but not beyond the other pieces, and other pieces in the same lattice. If TA can no longer move a pawn when it is a person's turn, he will be judged negative. Now each test data given a situation, if Georgia will win, output "Georgia will win", if Bob would win, output "Bob would win", if unsure, output "not sure". Two people know what the winning strategy is and will find ways to win.
Idea: Take the second example as an example:
1 5 6 7 9 12 14 17
The first piece cannot move to the left. The second piece can move 3 squares to the left. The third piece cannot be moved, and so on, you can get a sequence like this:
0 3 0 0 1 2 1 2, the nth number represents the number of steps that the nth piece can move.
Consider the case where the second piece moves to the left by one grid, the original sequence becomes:
0 2 1 0 1 2 1 2
This is the "second pile" of stones moved to the right of the "third pile" stone? This gives you a new definition of the equivalent game:
Given n heap of stones, the number of stones inside each heap is non-negative. Each time you can move any stone in the heap to the i + 1 heap (1 <= i < N), or the nth heap to throw away any of the stones. If someone cannot continue the operation then the sentence is negative.
Note that the right side of the piece is not always fixed, because to ensure that the difference or value is 0, so the right side of the pieces to move.
Consider this problem as the movement of each stone relative to the previous one.
#include <iostream>#include<algorithm>using namespacestd;intMain () {intT; CIN>>T; while(t--) { //Note that in the case of a circular run is 1 to n in the operation process must not be considered a[0] default to 0 new defined array a[0] not necessarily 0 intn,a[1005],ans=0; CIN>>N; for(intI=0; i<n;i++) Cin>>A[i]; Sort (A,a+N); for(inti=n-1; i>=1; i--) A[i]=a[i]-a[i-1]-1; a[0]-=1; for(inti=n-1; i>=0; i-=2) ans^=A[i]; if(ans) cout<<"Georgia would win"<<Endl; Elsecout<<"Bob would win"<<Endl; } return 0;}
POJ1704 Georgia and Bob (ladder game)