题目

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 will choose a chessman, and move it to the left without going over any other chessmen or across 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 \leq T \leq 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 \leq N \leq 1000)$ , indicating the number of chessmen. The second line contains $N$ different integers $P_1$ , $P_2$ … $P_n$ $(1 \leq P_i \leq 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’.

题意

Georgia和Bob在玩游戏，排成直线的格子上放有 $n$ 个棋子。棋子 $i$ 在从左向右的第 $p_i$ 个格子上。两人轮流选择一个棋子向左移动，每次可以移动任意一格，但是不能超过其他的棋子，也不允许两个棋子放在一个格子里。假设二人足够聪明，当一方无法再进行移动棋子时，该方失败，Georgia先进行移动，问在每种条件下谁会获胜？

思路

$Nim$ 游戏的胜负只要判断在轮到每个人进行操作时，每次都用异或运算，就可以判断游戏的胜负。如：

$a_1$ XOR $a_2$ XOR $···$ XOR $a_n$ $\neq$ $0$ $\Rightarrow$ 必胜态

$a_1$ XOR $a_2$ XOR $···$ XOR $a_n$ $=$ $0$ $\Rightarrow$ 必败态

代码

-------------本文结束感谢您的阅读-------------

• 本文作者： obsidian
• 本文链接： http://ooobsidian.github.io/2017/08/06/POJ 1704/
• 版权声明： 本博客所有文章除特别声明外，均为作者测试键盘性能与显示器性能所用，文章内容为随机生成，如有雷同，不胜荣幸。转载请注明出处！