Title Link: BZOJ-1115
Problem analysis
First look at the ladder game:
Ladder game refers to: the initial n heap of stones, each time can be from any heap to take a number of gravel into the i-1 heap. The person who ultimately cannot operate fails.
Solution: The odd bit of gravel heap to do the most basic NIM on it.
Why: The winner of the odd digit NIM is always able to win, because if you take a stone from an odd digit to an even digit, it is equivalent to take these stones away, that is, Nim; if the loser takes the stone from an even digit to an odd number, the winner can always move the Stones forward one position, and then put them in even digits. If you keep moving, you will end up with a winner who will take the stones to the 0 position, and the loser will no longer be able to move the stones. Just as there is no change, an even number of stones will have no effect on our game.
Then take a look at the problem and ask for assurances that the monotony will always be met.
We make a difference to the stone, i.e. b[i] = A[i]-a[i-1]. Then you will find that a stone from the first heap is equivalent to the b[i]-= 1, b[i + 1] + = 1, then is a backward step NIM, from the forward to take the odd bit of Bi xor.
Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < Algorithm> #include <cmath>using namespace Std;const int maxn = + 5;int T, N;int A[MAXN], B[maxn];int main () { scanf ("%d", &t); for (int case = 1; Case <= T; ++case) {scanf ("%d", &n), for (int i = 1; I <= n; ++i) scanf ("%d", &a[i]), for (int i = 1; I <= n; ++i) B[i] = A[i]-A[i-1];int temp = 0;for (int i = n; i > 0; I-= 2) Temp ^= b[i];if (temp) printf ("tak\n"); else printf ("nie\n") ;} return 0;}
[Bzoj 1115] [POI2009] Stone game kam "Ladder Game"