• poj 1704 Georgia and Bob


     
     

    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? 
     
    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
     
     
     
    思路:

    一个棋子每一次向左移的最大步数是固定的,而且随着移动减少,不是和取石子很像么?那么和取石子的区别在哪呢?就在于每一次移动时都会让右边相邻的那颗棋子移动空间变大,这样就和取石子只减不增有所不同了,我们应该怎样解决这个问题呢?
            我们并不放弃将其与我们熟悉的取石子对应,但我们将策略做小小的变动:
                        
            将棋子从右端向左端每相邻两个分为一对,如果只剩一个就将棋盘左端加一格放一颗棋子与之配对,这样配对后好像和以前没有什么区别,但决策时就方便多了,因为我们大可不必关心组与组之间的距离,当对手移动一组中靠左边的棋子时,我们只需将靠右的那一颗移动相同步数即可!同时我们把每一组两颗棋子的距离视作一堆石子,在对手移动两颗棋子中靠右的那一颗时,我们就和他玩取石子游戏,这样就把本题与取石子对应上了。
       简单说:/*由于任何两个相邻的棋子只与他们之间的空位有关,所以可以转化为普通的Nim游戏:我们可以把这些空位看作是石子数,谁取得了最后一个空位,谁就是赢家。*/

     

    代码:

     

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
      int a[1001],i,t,n,sg;
      scanf("%d",&t);
      while(t--)
      {
       sg=0;
       scanf("%d",&n);
       for(i=0;i<n;i++)
             scanf("%d",&a[i]);
       if(n%2!=0)
        a[n++]=0;
       sort(a,a+n);
       for(i=0;i<n;i+=2)
        sg^=a[i+1]-a[i]-1;
       if(sg==0)
        printf("Bob will win ");
       else
        printf("Georgia will win ");

     

      }
    }

     

  • 相关阅读:
    advisor调优工具优化sql(基于sql_id)
    关于等待事件cursor: pin S
    队列等待之enq: TX
    HTML5+CSS3从入门到精通 中文pdf完整版[229MB] 下载
    unity 控制透明度
    unity 限制模型移动的边界
    unity监测按下键的键值并输出+unity键值
    unity EventTrigger与模型
    wpf 获取桌面上的鼠标位置
    unity 代码更换ugui中image的关联素材
  • 原文地址:https://www.cnblogs.com/lxm940130740/p/3268079.html
Copyright © 2020-2023  润新知