列表

详情


NC51095. Georgia and Bob

描述

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? 

输入描述

The first line of the input contains a single integer T , the number of test cases. Then T cases follow. Each test case contains two lines. The first line consists of one integer N, indicating the number of chessmen. The second line contains N different integersP_1, P_2 ... P_n, which are the initial positions of the n chessmen.

输出描述

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'.

示例1

输入:

2
3
1 2 3
8
1 5 6 7 9 12 14 17

输出:

Bob will win
Georgia will win

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 492K, 提交时间: 2019-11-02 22:06:19

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int t;
	cin >> t;
	while( t-- )
	{
		int a[1005];
		int n;
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		int ans = 0;
		sort(a,a+n);
		for (int i = n - 1; i >= 0; i-= 2)
		{
			if( i == 0 )
			{
				if( a[i] != 1 ) ans ^= (a[i] - 1);
			}
			else ans ^= (a[i] - a[i-1] - 1); 
		}
		if( ans == 0 ) cout << "Bob will win" << endl;
		else cout << "Georgia will win" << endl;
	}
	return 0;
}

C++ 解法, 执行用时: 3ms, 内存消耗: 284K, 提交时间: 2021-08-08 11:40:05

#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e3 + 7;
int a[MAXN];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
		sort(a + 1,a + n + 1);
		int ans = 0;
		for(int i = n;i > 0;i -= 2)
		ans ^= (a[i] - a[i - 1] - 1);
		if(ans)
		puts("Georgia will win");
		else
		puts("Bob will win");
	}
	return 0;
}

上一题