Good luck in CET-4 everybody! Problem description CET4 is coming soon. Are you reviewing it hard? Maybe even the short term ACM has no time to practice. I know Kiki and Cici. Of course, Kiki and Cici, as contemporary college students infiltrated more than a dozen years in the test room, better understand the relaxation before the test. The so-called "Zhang Chi youdao" means this. No, Kiki and Cici have to play cards for a while before taking a rest every night to relax their nerves.
"Upgrade "? "Double buckle "? "Red Five "? Or "Landlords "?
Of course not! That's cool ~
As a computer school student, Kiki and Cici did not forget their major when playing cards. The rules for playing cards are as follows:
1. A total of N cards;
2. Both parties take turns to capture cards;
3. The number of cards each time can only be a power of 2 (I .e., 1, 2, 4, 8, 16 ...)
4. After the cards are captured, the winning and losing results also come out: the people who have finished the cards are the winners;
Suppose Kiki and Cici are both smart enough (in fact, you don't have to assume that there are unintelligent students ~), In addition, Kiki takes the cards first. Who can win?
Of course, no matter who wins cards are not a problem, it is important that the upcoming CET-4 can have a good state.
Good luck in CET-4 everybody!
The input data contains multiple test cases. Each test case occupies one row and contains an integer N (1 <=n <= 1000 ).
Output if Kiki can win, output "Kiki"; otherwise, output "Cici". The output of each instance occupies one line.
Sample Input
13
Sample output
KikiCici
Authorlcy
Sourceacm short term exam_2007/12/13
Solution:
1. Game Theory SG function can be used to solve the problem.
Based on the relationship of the NP graph, it is found that when n % 3 = 0, Cici wins; otherwise, Kiki wins
2. Use DP to solve the problem. Use DP [N] [f] to indicate who wins if n cards are left.
Solution code:
1. sg Search rules
#include <iostream>#include <cstdio>using namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF){ if(n%3==0) printf("Cici\n"); else printf("Kiki\n"); } return 0;}
2. DP Method
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn=1100;int dp[maxn][2];int DP(int n,int f){ if(n<=0) return 1-f; if(dp[n][f]!=-1) return dp[n][f]; if(f==0){ int ans=1; for(int i=1; i<=n ;i=(i<<1) ){ if(DP(n-i,1-f)<ans ) ans=DP(n-i,1-f); } return dp[n][f]=ans; }else{ int ans=0; for(int i=1; i<=n ;i=(i<<1) ){ if(DP(n-i,1-f)>ans ) ans=DP(n-i,1-f); } return dp[n][f]=ans; }}int main(){ memset(dp,-1,sizeof(dp)); int n; while(scanf("%d",&n)!=EOF){ if(DP(n,0)==0) printf("Kiki\n"); else printf("Cici\n"); } return 0;}