Georgia and Bob 格鲁吉亚和鲍勃
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 13319 Accepted: 4461
时间限制: 1000MS 内存限制: 10000K
提交总数: 13319 接受: 4461
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:
他们在纸上绘制一排网格,将网格从左到右依次为1,2,3,…,并将N个西洋棋棋子放在不同的网格上,如下图所示:
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?
鉴于n个西洋棋棋子的初始位置,你能预测谁将最终赢得比赛吗?
Input 输入
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases.
输入的第一行包含单个整数T(1 <= T <= 20),即测试用例的数量。
Then T cases follow.
然后是T案例。
Each test case contains two lines.
每个测试用例包含两行。
The first line consists of one integer N (1 <= N <= 1000), indicating the number of chessmen.
第一行由一个整数N(1 <= N <= 1000)组成,表示西洋棋棋子的数量。
The second line contains N different integers P1, P2 … Pn (1 <= Pi <= 10000), which are the initial positions of the n chessmen.
第二行包含N个不同的整数P1,P2 … Pn(1 <= Pi <= 10000),它们是n个西洋棋棋子的初始位置。
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
Code
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
string ans[1000];
int t, n, p[1000];
string deal(int pInt[],int n) {
std::sort(pInt, pInt + n);
int result = 0;
if ((n & 1) == 1)
for (int i = 0; i < n; i += 2)
result ^= (i == 0) ? (pInt[0] - 1) : (pInt[i] - pInt[i - 1] - 1);
else
for (int i = 1; i < n; i += 2)
result ^= (pInt[i] - pInt[i - 1] - 1);
if (result) return "Georgia will win";
else return "Bob will win";
}
int main() {
cin >> t;
for (int i = 0; i < t; ++i) {
cin >> n;
memset(p, 0, sizeof(p));
for (int j = 0; j < n; ++j)
cin >> p[j];
ans[i] = deal(p,n);
}
for (int i = 0; i < t; ++i)
cout << ans[i] << endl;
return 0;
}