[Original blog] poj 1704 Georgia and Bob

Source: Internet
Author: User

Question Link
Question:

Georgia and Bob are playing games. There is an infinitely long boardNFlagiThe position of a piece can be usedPi. Georgia should leave now. Each time, a pawn can move any lattice to the left, but it cannot surpass other pawns or be in the same lattice as other pawns. If it is the turn of a person, he or she will not be able to move the pawns any more. Now each test data is given a situation where, if Georgia wins, "Georgia will win" is output. If Bob wins, "Bob will win" is output. If not, "not sure" is output ". Both know what the winning strategy is and will try to win.

First of all, it is impossible for a game without a draw to "not sure". Each State is either a victory or a defeat. See the definition.
We found that only one flag can be moved to the left at a time, so the distance between the flag is closely related. The distance shown on the image is:0,1,2,0, As a series.
Then pay attention to moving a flag each time, which actually reduces the number of columns.x, The next number in the sequence increasesx. (If you moveN(Only decrease without increasing)
We divide the numbers in the series into two types:Class: By the number of ColumnsNItem,N-2,N-4,N-6...... Item; the other isClass B: By the number of ColumnsN-1Item,N-3,N-5,N-7...... .
In this way, each operation actually reduces the number of class A and increases the number of Class B. (Or onlyNItems)
We can proveThe number in Class B does not affect the outcome.
Symmetric gameWhich has a person moving the number of columns in Class BiItem, then another person can move the flag that he moved last time to the next Diski+2Item, pay attention to Class B, know to move toNSo far.

So if we only look at the number of class A, it would be a nim stone game, and XOR would be better.

PS. Sorting is required after reading (the samples are sorted.

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring> //by zrt//problem:using namespace std;typedef long long LL;const int inf(0x3f3f3f3f);const double eps(1e-9);int tt;int a[1005];int b[1005];int main(){    #ifdef LOCAL    freopen("in.txt","r",stdin);    freopen("out.txt","w",stdout);    #endif    scanf("%d",&tt);    while(tt--){        int n;        scanf("%d",&n);        for(int i=1;i<=n;i++) scanf("%d",&a[i]);        sort(a,a+n+1);        for(int i=1;i<=n;i++) b[i]=a[i]-a[i-1]-1;        int sg=0;        for(int i=n;i>0;i-=2){            sg^=b[i];        }        if(!sg) puts("Bob will win");        else puts("Georgia will win");    }        return 0;}
View code

 

[Original blog] poj 1704 Georgia and Bob

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.