The grundy value of poj 3537 Crosses and Crosses Game Theory
Question:
For a 1 * n grid, take turns on the top of the Cross, first draw three consecutive cross-forks to win, and ask whether the first hand wins or loses.
Analysis:
Find the grundy value of the status (that is, the sg value). For details, see the code. Why do you want to think about it? I can only think about it. (others say they want to see game theory ).
Code:
// Poj 3537 // sep9 # include
# Include
Using namespace std; int grundy [2048]; int h [2048]; int get_grundy (int n) {if (n <0) return 0; if (grundy [n]! =-1) return grundy [n]; int h [2048]; memset (h, 0, sizeof (h); for (int I = 1; I <= n; + + I) {int t = get_grundy (I-3) ^ get_grundy (n-i-2); h [t] = 1 ;}int I; for (I = 0; h [I]; ++ I); return grundy [n] = I;} int main () {int n; memset (grundy,-1, sizeof (grundy )); grundy [0] = 0, grundy [1] = 1, grundy [2] = 1, grundy [3] = 1; while (scanf ("% d", & n) = 1) if (get_grundy (n )! = 0) puts ("1"); elseputs ("2"); return 0 ;}