Game SG Functions
SG functions are very esoteric. I don't understand.
The method of SG function. A stone string is divided into two or one parts. If there are two parts, the SG values in the two States are used for different or processing. I don't know why ....
# Include <iostream> # include <cstring> # include <cstdio> # include <algorithm> using namespace STD; int N, K; int temp; int s [150]; int SG [2000]; bool vis [2005]; int SG (int x) // perform a memory-based search {If (SG [x]! =-1) return SG [X]; else {memset (VIS, 0, sizeof (VIS); For (INT I = 0; I <n & S [I] <= x; I ++) for (Int J = 0; J + S [I] <= x & J <X/2 + 1; j ++) vis [SG (j) ^ SG (X-s [I]-j)] = 1; for (INT I = 0; I ++) if (! Vis [I]) return SG [x] = I ;}int main () {While (CIN> N) {for (INT I = 0; I <N; I ++) scanf ("% d", & S [I]); sort (S, S + n); CIN> K; memset (SG,-1, sizeof (SG); SG [0] = 0; while (k --) {scanf ("% d", & temp); If (SG (temp )) cout <"1" <Endl; elsecout <"2" <Endl ;}} return 0 ;}