BZOJ1115
Meaning of the title: game Nim ladder effect: each step on a pile of stones, two stones push people to play games on the ladder. A stack push may be any number of stones per one step to the left, all the stones are pushed to the next step that is considered successful, i.e., the output can not be pushed.
Analysis: According to the idea of Nim ladder, pushing even-heap (even index) is not meaningful (see links ), simply ask Nim and the odd heap, and that is XOR.
#include<bits/stdc++.h> using namespace std; int a[10005]; int main(){ int T; scanf("%d",&T); while(T--){ int ans=0,n; scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]); for(int i=n;i>1;i-=2) ans^=(a[i]-a[i-1]); if(n&1) ans^=a[1]; printf(ans ? "TAK\n" : "NIE\n"); } return 0; }
P2575
topic
You are given a chessboard n * 20, and there are a number of pieces on the board, ask who won? akn upper hand!
Rules of the game is this:
For one piece, it can move one space to the right, if there is the right piece, skip the first space to the right, if there is no space on the right, you can not move this piece, if all the pieces can not move, it will lose this match.
Analysis: two spaces between the number of pieces is regarded as a bunch of the same only the odd heap of Nim and demand.
#include <cstdio> #include <CString> int T, N, K, CNT, TOT, X, ANS1, ANS2; BOOL VIS [ 23 is ]; // VIS [i] == Location i to true indicates stone int main ( ) { Scanf ( " % D " , & T); the while (T-- ) { Scanf ( " % D " , & N); ANS2 = 0 ; // SG value of the entire data stored by ANS2 the while (the N-- ) { Scanf ( " % D " , & K); Memset (VIS,to false , the sizeof (VIS)); CNT = 20 is -K + . 1 ; TOT = 0 ; ANS1 = 0 ; // CNT i.e. C, tot the number of storage pieces the current step, ans1 Bank SG value stored the while (K-- ) { Scanf ( " % D " , & X); VIS [X] = to true ; // labeled with stones } for ( int I = . 1 ; I <= 20 is ; ++ I) { IF (! VIS [I]) { IF ((--cnt) & . 1 ) ANS1 ^ = TOT; // odd-step, the exclusive OR TOT = 0 ; } the else ++ TOT; // Add the pieces to the step } ANS2 ^ = ANS1; // SG Theorem } IF (ANS2) the printf ( " YES \ n- " ); the else the printf ( " NO \ n- " ); } return 0 ; }
Reference links:
1. https://blog.csdn.net/liangzhaoyang1/article/details/51213003