POJ 1704 Georgia and Bob (ladder game)

Source: Internet
Author: User

Georgia and Bob
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 8656 Accepted: 2751

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

Source

POJ monthly--2004.07.18

Ideas

Ladder game

The space between the pieces as a pile of stones, the problem can be transformed into a class of things called Ladder game.

That

If the opponent takes a coin on an odd digit, we also resemble Nim taking a coin on an odd digit to return the SG value to 0;

If the other person takes a coin on an even digit. Then we'll just upload the number of coins that he just uploaded from the odd digits to the singular digits.

Returns the even digits unchanged. This will keep the sg=0;

So the ladder problem is seen as an odd-numbered Nim game.

Code

1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5 inta[1001],n;6 7 intMain () {8     intT;9scanf"%d",&T);Ten      while(t--) { Onescanf"%d",&n); A          for(intI=1; i<=n;i++) -scanf"%d",&a[i]); -Sort (A +1, a+n+1); the         intans=0, s=0; -          for(intI=n;i>0; i-=2) -ans^=a[i]-a[i-1]-1; -         if(ANS) puts ("Georgia would win"); +         ElsePuts"Bob would win"); -     } +     return 0; A}

POJ 1704 Georgia and Bob (ladder game)

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.