1115: [POI2009]石子游戏Kam
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1061 Solved: 651
[ Submit][ Status][ Discuss]
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
2
2 2
3
1 2 4
Sample Output
NIE
TAK
TAK
HINT
感谢MT大牛翻译.
Source
由于取了一堆石子, 相当于就是说与前面的差值变小了,与后面的差值变大了,这让我们有点熟悉——很像阶梯nim.我们把差值作为石子,那么相当于就是把一堆石子抽一部分给下一堆,这就等价于阶梯nim.
阶梯nim的讲解: 点这里
#include<stdio.h>
inline const int read(){
register int x = 0;
register char ch = getchar();
while(ch < '0' || ch > '9') ch = getchar();
while(ch >= '0' && ch <= '9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();
return x;
}
int T, n, last, x, ans;
int main(){
T = read();
while(T--){
ans = 0; last = 0;
n = read();
for(register int i = 1; i <= n; ++i){
x = read();
if((n-i-1) & 1) ans ^= (x-last);
last = x;
}
(ans) ? puts("TAK") : puts("NIE");
}
}