Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1847
This is exactly the same as toj1180.
Use the SG function. Enter the SG value in 1000 to the table.
Code:
/* # Include <cstdio>
Int main (){
Int N;
While (~ Scanf ("% d", & N )){
If (N % 3) printf ("Kiki \ n ");
Else printf ("Cici \ n ");
}
Return 0;
}*/
# Include <cstdio>
# Include <cstring>
Int SG [1001], a [11];
Void Init (){
Memset (SG,-1, sizeof (SG ));
SG [0] = 0, SG [1] = 1;
A [0] = 1;
For (INT I = 1; I <10; I ++ ){
A [I] = A [I-1] * 2;
SG [A [I] = 1; // The Node SG that can win in one step is 1
}
}
Int Mex (int n) {// SG [N] = Mex (SG [m]), M is followed by N
If (SG [N]! =-1) return SG [N];
For (INT I = 0; I <10; I ++ ){
Int temp = n-A [I];
If (temp <0) break;
If (SG [temp] = 0 | SG [temp] =-1 &&! Mex (temp )){
// N can be one step to the point where SG is 0
SG [N] = 1;
Return 1;
}
}
SG [N] = 0;
Return 0;
}
Int main (){
Int N;
Init ();
Mex (1000); // calculates the SG Value
While (~ Scanf ("% d", & N )){
If (SG [N]) printf ("Kiki \ n ");
Else printf ("Cici \ n ");
}}