2015年9月25日 星期五

[HOJ]20 堆石頭遊戲

若剩下偶數組兩兩石頭數目一樣的堆
先取者必輸
剩下的就普通Nim遊戲


#include<cstdio>
int main(){
    int n,p,tmp,T,now;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        now=p=0;
        for(int i=0;i<n;i++){
            scanf("%d",&tmp);
            if((n-i)%2){
                now^=tmp-p;
            }
            p=tmp;
        }
        if(now)puts("TAK");
        else puts("NIE");
    }
}

沒有留言:

張貼留言