zoukankan      html  css  js  c++  java
  • Georgia and Bob POJ

    $ color{#0066ff}{ 题目描述 }$

    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: img 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?

    (color{#0066ff}{输入格式})

    The first line of the input contains a single integer T (1 <= T <=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 <= 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.

    (color{#0066ff}{输出格式})

    For each test case, prints a single line, "Georgia will win", if Georgiawill win the game; "Bob will win", if Bob will win the game; otherwise 'Not sure'.

    (color{#0066ff}{输入样例})

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

    (color{#0066ff}{输出样例})

    Bob will win
    Georgia will win
    

    (color{#0066ff}{数据范围与提示})

    none

    (color{#0066ff}{题解})

    移动一个棋子,与左边的距离减小,与右边的距离增大

    可以抽象成几堆石子,从一堆拿到另一堆,这就是阶梯NIM了

    #include <cctype>
    #include <cstdio>
    #include <algorithm>
    
    #define LL long long
    LL in() {
    	char ch; LL x = 0, f = 1;
    	while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
    	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
    	return x * f;
    }
    const int maxn = 2050;
    int a[maxn], b[maxn];
    int main() {
    	for(int T = in(); T --> 0;) {
    		int n = in();
    		for(int i = 1; i <= n; i++) a[i] = in();
    		std::sort(a + 1, a + n + 1);
    		int ans = 0;
    		for(int i = n; i >= 1; i -= 2)
    			ans = ans ^ (a[i] - a[i - 1] - 1) ;		
    		puts(!ans? "Bob will win" : "Georgia will win");
    	}
    	return 0;
    }
    
  • 相关阅读:
    一网友推荐的书:框架设计(第2版):CLR Via C#
    线程与WinForm设计,防冻结,卡住窗体
    通用数据库操作辅助类DbHelper
    高级着色器语言(High Level Shader Language,简称HLSL)
    无法将 匿名方法 转换为类型“System.Delegate”,因为它不是委托类型
    根据RGB,计算灰度值
    温故而知新:WinForm/Silverlight多线程编程中如何更新UI控件的值
    [原创视频]PHP在netbeans中的简单使用
    自己封装的ASP.NET的SQLITE数据库的操作类
    《JavaScript征途》读后感
  • 原文地址:https://www.cnblogs.com/olinr/p/10491697.html
Copyright © 2011-2022 走看看