zoukankan      html  css  js  c++  java
  • BZOJ 1115: [POI2009]石子游戏Kam [阶梯NIM]

    传送门

    有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数。两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏。问先手是否必胜。


    一眼差分,然后,这不是阶梯$NIM$吗?

    阶梯$NIM$只考虑奇数位置进行$NIM oplus$起来就可以了,因为偶数位置是对称的我们有平衡的操作

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    const int N=1005;
    inline int read(){
        char c=getchar();int x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
        return x*f;
    }
    int n,a[N];
    int main(){
        freopen("in","r",stdin);
        int T=read();
        while(T--){
            n=read();
            int ans=0;
            for(int i=1;i<=n;i++) a[i]=read();
            for(int i=n;i>=1;i--) a[i]-=a[i-1];
            for(int i=n;i>=1;i-=2) ans^=a[i];
            if(ans) puts("TAK");
            else puts("NIE");
        }
    }
  • 相关阅读:
    docker基础
    paas平台
    django 多数据分库
    s3对象存储
    css
    __construct()和__initialize()
    js function
    phpstorm ftp 使用
    php
    thinkphp 笔记
  • 原文地址:https://www.cnblogs.com/candy99/p/6544569.html
Copyright © 2011-2022 走看看