Georgia and Bob
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total submissions: 9321 |
|
accepted: 3036 |
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 in most contains one single Chessman. The player who cannot make a move loses the game.
Georgia always plays-since "lady-a". Suppose that Georgia and Bob both does their best in the game i.e., if one of them knows a way to win the game, he or she w Ill be able to carry it out.
Given the initial positions of the N chessmen, can you predict who would finally win the game?
Input the ' the ' input contains a single integer t (1 <= t <=), the number of test cases. Then T cases follow. Each test case contains two lines. The 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, "Georgia'll Win", if Georgia would win the game; "Bob would win", if Bob would 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 would win
Georgia'll win
to a 1*m board, there are n pieces, each can only move the pawn to the left, and at least move one step, two people rotating operation, who can not move who lost.
It's obviously a game problem, we can calculate the distance between the adjacent pieces in the whole chessboard, the artificial operation may make this distance increase, also may let it reduce, but, every two operations, regardless of how to move the pieces, we can assume that this distance will be reduced, so, The distance is equal to the number of stones, two people take the stone, to see who took the last stone. This translates into a Nim game, but what if the number of pieces on the chessboard is odd? We can add a piece, at the far left of the chessboard, that is, its position is 0, the number of stones per pile can be considered to be adjacent to each of the two pieces of distance difference, and then calculate the differences or, to determine the value of the results obtained.
AC Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm
> #include <queue> using namespace std;
int main () {int t;
cin>>t;
while (t--) {int n;
cin>>n;
int a[n+10],s=0;
for (int i=0; i<n; i++) cin>>a[i];
if (n&1) a[n++]=0;
Sort (a,a+n);
for (int i=1; i<n; i+=2) s^=a[i]-a[i-1]-1;
if (s) cout<< "Georgia'll Win" <<endl;
else cout<< "Bob would win" <<endl;
return 0; }