int SG [MAXN]; // SG [n-] n-represents the number of each pile int S [K]; // value can take each of the subscripts starting from 0, 0 ~ k-1, must be ordered, can sort ( s, s + K); BOOL VIS [MAXN]; const int K; // K is set s the size of the void get_sg () { int I, J; for (I = 0 ; I <MAXN; I ++ ) { Memset ( VIS, 0 , the sizeof (VIS)); J = 0 ; the while (J <K && S [J] <= I) { VIS [SG [I -s [J]]] = . 1 ; J ++ ; } for (J = 0 ; J <MAXN; J ++ ) IF (! VIS [J]) { SG [I] = J; BREAK ; } } } int main () { ... // the s array initialization Memset (SG, - . 1 , the sizeof (SG)); get_sg (); IF (SG [n-] == 0 ) // sente losing the else // upper hand win // If multiple stacks, then //SG = NUM [N1] ^ SG [N2] ^ SG [N3] ^ ^ .... SG [NX]; // IF (NUM == 0) losing the upper hand // the else win the upper hand ... }
Good Luck in CET-4 Everybody!
HDU - 1847
Meaning of the questions: n cards (1 <= n <= 1000), two people take turns cards, can only take the power of two cards (ie: 1,2,4,8,16 ...), and finally caught End Signs of winning
Solution: pile, s array value is 2 ^ i (0 <= i <= 11)
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<stack> #include<cstdlib> #include<queue> #include<set> #include<string.h> #include<vector> #include<deque> #include<map> using namespace std; #define INF 0x3f3f3f3f #define eps 1e-4 #define bug printf("*********\n") #defineDebug (X) X COUT << # "= [" << << X "]" << endl typedef Long Long LL; typedef Long Long LL; const int MAXN = 1E3 + . 5 ; const int MOD = 998 244 353 ; #define 12 is K int SG [MAXN]; // SG [n-] n-represents the number of each pile int S [K]; // value can take each of the subscripts starting from 0, 0 ~ k-1, must be ordered and to be Sort (S, S + K); BOOL VIS [MAXN]; void get_sg () { int I, J; for (I = 0 ; I <MAXN; I ++ ) { Memset (VIS,0, sizeof(vis)); j = 0; while (j < k && s[j] <= i) { vis[sg[i - s[j]]] = 1; j++; } for (j = 0; j < maxn; j++) if (!vis[j]) { sg[i] = j; break; } } } int main() { int n; for(intI = 0 ; I <K; I ++ ) S [I] = int (POW ( 2 , I)); the while (CIN >> n-) { Memset (SG, - . 1 , the sizeof (SG)); get_sg (); IF (SG [n-] == 0 ) // upper hand losing the puts ( " Cici " ); the else the puts ( " Kiki " ); // upper hand win } // If multiple stacks, the // NUM = SG [ n1] ^ sg [n2] ^ sg [n3] ^ .... ^ sg [nx];// IF (NUM == 0) losing the upper hand // the else upper hand win }