bzoj1115:[POI2009]石子游戏Kam
传送门
阶梯nim模型
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=1e5+10;
int n,T,ans,a[maxn],b[maxn];
int main()
{
read(T);
while(T--)
{
read(n),ans=0;
for(rg int i=1;i<=n;i++)read(a[i]);
for(rg int i=1;i<=n;i++)b[i]=a[i]-a[i-1];
for(rg int i=n;i>=1;i-=2)ans^=b[i];
if(ans)printf("TAK\n");else printf("NIE\n");
}
}