题目是一个nim游戏的改版
可能各位大牛看来不成问题,但是萌新入手还是不错的
只需要前后两个看成一个石子堆就可以了。
可能会与疑问,棋子往左石子堆就增加了,但是右边的棋子移动,就石子堆减少了,可以回到原来的状态,所以可以用nim游戏的解法。
奇数个棋子就把其中一个单独拿出来就行了,或者往里面加一个位置为0的。
然后有个坑是数据是没经过排序的。这里wa了2次,果然萌新。
#include<math.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=10000+100;
int p[maxn];
int main()
{
int T;
cin>>T;
while(T--){
int n;
cin>>n;
int x=0;
for(int i=0;i<n;i++)
scanf("%d",&p[i]);
int i=0;sort(p,p+n);
if(n%2){
x^=(p[0]-1);
i++;
}
for(;i<n;i+=2){
x^=(p[i+1]-p[i]-1);
}
if(x)cout<<"Georgia will win"<<endl;
else
cout<<"Bob will win"<<endl;
}
return 0;
}