[POI2009]KAM-Pebbles

Turn to step Nim to do:

Let a[i] denote the number of stones in the i-th pile, and c[i] denote a[i]-a[i-1], then the number of stones we can take in each pile is c[i].
Since the initial number of pebbles is not strictly ascending, and each state needs to keep the number of pebbles in not strictly ascending order, then we now assume that x is removed in the i-th pile, and a[i] becomes a[i] -x, c[i] becomes c[i]-x, c[i+1] becomes c[i+1]+x, which is equivalent to transferring the x stones available in the i-th pile to i +1 stack (a[i]-x>=a[i-1], that is, x<=c[i]).
In other words, we can take x stones from a pile of stones and transfer them to the next step from the stones representing the ladder Nim. The maximum limit of x is: the original number of stones in the ladder.
And when the stones can be transferred from the stone pile of Nim, the number of stones removed from the original stone pile is legal.
Therefore, we can directly do an upside-down ladder Nim for the pile of stones representing the ladder Nim.
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+5;
int T,n,ans;
int a[N],c[N];
int main(){
    
    
	scanf("%d",&T);
	while (T--)
	{
    
    
		ans=0;
		scanf("%d",&n);
		for (register int i=1; i<=n; ++i) scanf("%d",&a[i]);
		for (register int i=1; i<=n; ++i) c[i]=a[i]-a[i-1];
		for (register int i=n; i>=1; i-=2) ans^=c[i];
		if (ans) puts("TAK");
		else puts("NIE");
	}	
return 0;
}

Guess you like

Origin blog.csdn.net/Dove_xyh/article/details/108133740