码迷,mamicode.com
首页 > 其他好文 > 详细

[POI2009]石子游戏Kam

时间:2019-02-16 13:54:32      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:href   代码   names   pre   define   printf   ref   stream   algorithm   

传送门

阶梯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"); 
    }
}

[POI2009]石子游戏Kam

标签:href   代码   names   pre   define   printf   ref   stream   algorithm   

原文地址:https://www.cnblogs.com/lcxer/p/10387407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!