POJ1704 Georgia and Bob

题目地址

题解

这个模型,没记错是叫做阶梯博弈
他这个模型可以转化成Nim游戏。
把每一对移动的棋子之间的间距看作是石头的数目,就可以依靠Nim游戏的结论进行解答。但是为什么这样的转化是正确的呢?
首先两个棋子逼近,就相当于取走若干个石头;如果两个石头远离,那么不要紧,下一步可以把这个多出来的部分减掉去,所以还是相当于没有增加。
如果石头个数是奇数就虚拟一个边界上的石头和他配对。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
int f=1,x=0;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return f*x;
}
int T,n,a[1005];
void solve(){
T=read();
while(T--){
n=read();
for(int i=1;i<=n;i++)a[i]=read();
if(n&1)a[n+1]=0,n++;
sort(a+1,a+n+1);
int res=0;
for(int i=1;i<=n;i+=2)
res^=(a[i+1]-a[i]-1);
printf("%s\n",res?"Georgia will win":"Bob will win");
}
}
int main(){
solve();
return 0;
}