Question Link
Question:
Georgia and Bob are playing games. There is an infinitely long boardN
Flagi
The 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 ColumnsN
Item,N-2
,N-4
,N-6
...... Item; the other isClass B: By the number of ColumnsN-1
Item,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 onlyN
Items)
We can proveThe number in Class B does not affect the outcome.
Symmetric gameWhich has a person moving the number of columns in Class Bi
Item, then another person can move the flag that he moved last time to the next Diski+2
Item, pay attention to Class B, know to move toN
So 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