bzoj1115: [POI2009]石子游戏Kam 组合游戏

考虑将问题转化到阶梯NIM上来。
首先初始 i 格可以移掉的石子数 为 a[i]-a[i-1]
事实上,若我们从 i 处取走了 x 个石子,那么下一次及以后就可以在 i+1 处多取 x 个,相当于 把 i 处的 x 个石子加到了 i+1处.
问题就转化成了阶梯NIM。
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int n,save[1100];
int getint()
{
    int res;char c;
    while(c=getchar(),c<'0'||c>'9');
    res=c-'0';
    while(c=getchar(),c>='0'&&c<='9')
        res=res*10+c-'0';
    return res;
}
int main()
{
    int cas;
    cas=getint();
    while(cas--)
    {
        n=getint();
        for(int i=1;i<=n;i++)
        {
            save[i]=getint();
        }
        int ans=0;
        for(int i=n;i>1;i-=2)
        {
            ans^=save[i]-save[i-1];
        }
        if(n&1)ans^=save[1];
        if(ans) printf("TAK\n");
        else printf("NIE\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值