bzoj1115: [POI2009]石子游戏Kam

Description

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

Input

第一行u表示数据组数。对于每组数据,第一行N表示石子堆数,第二行N个数ai表示第i堆石子的个数(a1<=a2<=……<=an)。 1<=u<=10 1<=n<=1000 0<=ai<=10000

Output

u行,若先手必胜输出TAK,否则输出NIE。

Sample Input

2
2
2 2
3
1 2 4

Sample Output

NIE
TAK
 
见http://www.tuicool.com/articles/aARjYr
code:
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #define maxn 1005
 7 using namespace std;
 8 char ch;
 9 int T,n,a[maxn],tmp;
10 bool ok;
11 void read(int &x){
12     for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=1;
13     for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
14     if (ok) x=-x;
15 }
16 int main(){
17     for (read(T);T;T--){
18         read(n),tmp=0;
19         for (int i=1;i<=n;i++) read(a[i]);
20         for (int i=n;i>=1;i-=2) tmp^=(a[i]-a[i-1]);
21         if (tmp) puts("TAK");
22         else puts("NIE");
23     }
24     return 0;
25 }

 

posted @ 2015-08-09 15:00  chenyushuo  阅读(182)  评论(0编辑  收藏  举报