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

    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 9771   Accepted: 3220

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

    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
    

    Source

    博弈 脑洞题

    操作时,棋子可以向前移动某范围内的任意距离←联想到nim问题←联想到sg函数

    起初的想法是:将每个间隔长度看做nim游戏中的一堆石子长度,求所有间隔长度的异或和,若异或和为0,后手必胜。

    果断WA掉

    看到别人的解法是相邻棋子两两配对,每对之间的间隔当做nim石子。

    似乎很有道理。如果每个间隔都算的话,减小一个间隔就会增加另一个间隔,而如果两两配对的话,假设a在b前面,a走x格,b也可以多走x格使得状态不变。

     1 /*by SilverN*/
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cmath>
     7 #include<vector>
     8 using namespace std;
     9 const int mxn=10010;
    10 int read(){
    11     int x=0,f=1;char ch=getchar();
    12     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    13     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    14     return x*f;
    15 }
    16 int T,n;
    17 int a[mxn],cnt=0;
    18 int main(){
    19     int i,j,x;
    20     T=read();
    21     while(T--){
    22         n=read();
    23         int res=0;
    24         a[0]=0;
    25         for(i=1;i<=n;i++)a[i]=read();
    26         if(n&1)a[++n]=0;
    27         sort(a+1,a+n+1);
    28         for(i=1;i<=n;i+=2){
    29             res^=(a[i+1]-a[i]-1);
    30         }
    31         if(!res)printf("Bob will win
    ");
    32         else printf("Georgia will win
    ");
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    UIAction 公共界面访问控制(拦截控制)
    MD5加密
    SVN的简单用法
    Spring AOP基础之JDK动态代理
    Spring中的事务管理模块基础
    Spring添加Junit4支持
    Spring里面dbcp连接池的配置和使用
    vue.js自定义指令详解
    vue input输入框联想
    export ,export default 和 import 区别 以及用法
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6253525.html
Copyright © 2011-2022 走看看