Http://poj.org/problem? Id = 3537
Question:
The two draw X in turn on the 1 * n lattice. Each time they draw X on the blank lattice, if a player connects three X, the player wins. Whether your task is to determine whether it is a first-hand victory or a second-hand victory.
Ideas:
When you draw on paper, you will find that after you draw a grid, the two on the left and the two on the right cannot be painted (if any). That is to say, every time you draw a grid, five grids are excluded.
Therefore, it is divided into two parts: I-3 on the left and n-I-2 on the right. Use the SG function to solve the problem.
# Include <cstdio> # include <cstring> const int maxn = 2000 + 10; int SG [maxn]; int DFS (int n) {If (n <0) return 0; if (SG [N]! =-1) return SG [N]; bool vis [maxn]; memset (VIS, 0, sizeof (VIS); For (INT I = 1; I <= N; I ++) {vis [DFS (I-3) ^ DFS (n-I-2)] = 1 ;}for (INT I = 0; I <= N; I ++) {If (! Vis [I]) return SG [N] = I;} int main () {int N; memset (SG,-1, sizeof (SG); While (~ Scanf ("% d", & N) {printf ("% d \ n", DFS (n) = 0? 2: 1);} return 0 ;}
Poj 3537 crosses and crosses