您的位置:首页 > 其它

poj 1704 Georgia and Bob阶梯博弈

2016-11-20 11:29 429 查看
点击打开链接

把棋子两两组成一对,其距离看作nim中石子的数量

右边的棋子向左移动  距离减小 相当于在该堆中拿石子 

左边的棋子向左移动 距离增加 石子增多,但是下一步可以移动其右边的棋子,使之恢复至原来的状态

 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int N=1e5+20;
int p
,a
;

//nim石子全为0,必败态即异或为0
//异或为0必定转化到异或非0(异或消去律)
//异或非0&&=k 则将a[i]修改为a[i]^k,即可

int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
p[0]=0;
for(int i=1;i<=n;i++)
{
cin>>p[i];
}
sort(p+1,p+1+n);
int num=0;
if(n%2==0)
for(int i=2;i<=n;i+=2)
{
a[++num]=p[i]-p[i-1]-1;
}
else
for(int i=1;i<=n;i+=2)
{
a[++num]=p[i]-p[i-1]-1;
}

int ans=0;
for(int i=1;i<=num;i++)
ans^=a[i];

if(ans)
puts("Georgia will win");
else
puts("Bob will win");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: