poj1704 Georgia and Bob

来源:互联网 发布:51单片机p0口上拉电阻 编辑:程序博客网 时间:2024/04/29 17:39

Problem:

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?

在 小媛在努力 和  博客集暗时间的督促下,第一次写博客,这几天开始认真做题,选了感兴趣的博弈题。好多主要靠思维联想的博弈题,比如说这题我觉得就比较绕。

这题的思路也是看了好几个题解才想明白。基本思路就把相邻的两个石子看做一堆,然后以期间的石子数目为石子数,然后就是最基本的nim问题了,其中的原理是利用一对的相对位置是可控的,也就是说对于每对中的前一个石子可前行的步数,后一个石子都是也可以移动相同的步数的。这样对间的距离就没有意义了,因为相当于每次进行这样的一个来回总局面的状态依然没有任何变化,对间的距离在不可消除时,只能在每对内部的距离进行缩减,和拾取石子的道理就一样了。当然,对于输的一方,可能对于破坏那个对间相对不变的规则是想打破的,但是赢得那方就会像规则中的活动一样还原状态。(奇数和位置0绑定)

总而言之,只有对以内的是可以选取的。规则的打破本来就是相对的,比如先手赢,先取得可以说是说石子中的某个特定的致输值,后手可以以相对移动来缓冲,但是一个来回状态就还是恢复了,先手继续移动此对后一个,总之,赢的人总是可以肆无忌惮的控制后一个。。

#include <cstdio>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1010;int pos[maxn];int main(){    int t,n;    cin>>t;    while(t--)    {        cin>>n;        for(int i = 1;i<=n;i++)            scanf("%d",&pos[i]);        int ans = 0;        sort(pos+1,pos+n+1);        pos[0] = 0;        for(int i = n;i>0;i-=2)            ans ^= (pos[i]-pos[i-1]-1);        if(ans)            printf("Georgia will win\n");        else            printf("Bob will win\n");    }    return 0;}


0 0
原创粉丝点击