HDU1847 Good Luck in CET-4 Everybody!

 

Good Luck in CET-4 Everybody!

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11418    Accepted Submission(s): 7408


Problem Description
大 学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此。当然,作为在考 场浸润了十几载的当代大学生,Kiki和Cici更懂得考前的放松,所谓“张弛有道”就是这个意思。这不,Kiki和Cici在每天晚上休息之前都要玩一 会儿扑克牌以放松神经。
“升级”?“双扣”?“红五”?还是“斗地主”?
当然都不是!那多俗啊~
作为计算机学院的学生,Kiki和Cici打牌的时候可没忘记专业,她们打牌的规则是这样的:
1、  总共n张牌;
2、  双方轮流抓牌;
3、  每人每次抓牌的个数只能是2的幂次(即:1,2,4,8,16…)
4、  抓完牌,胜负结果也出来了:最后抓完牌的人为胜者;
假设Kiki和Cici都是足够聪明(其实不用假设,哪有不聪明的学生~),并且每次都是Kiki先抓牌,请问谁能赢呢?
当然,打牌无论谁赢都问题不大,重要的是马上到来的CET-4能有好的状态。

Good luck in CET-4 everybody!
 

 

Input
输入数据包含多个测试用例,每个测试用例占一行,包含一个整数n(1<=n<=1000)。
 

 

Output
如果Kiki能赢的话,请输出“Kiki”,否则请输出“Cici”,每个实例的输出占一行。
 

 

Sample Input
1 3
 

 

Sample Output
Kiki Cici
 

 

Author
lcy
 

 

Source
 

 

Recommend
 
 
巴什博奕变形。
做法1:如果当前局面%3=0,则先手必败。因为无论先手怎么取,后手总能使之%3=0
做法2:打表,发现SG函数只有0,1,2三种情况
 

为了练习SG函数, 写一下SG函数版本的

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 #include <queue>
 7 #include <vector>
 8 #include <cmath> 
 9 #define min(a, b) ((a) < (b) ? (a) : (b))
10 #define max(a, b) ((a) > (b) ? (a) : (b))
11 #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
12 inline void swap(int &a, int &b)
13 {
14     int tmp = a;a = b;b = tmp;
15 }
16 inline void read(int &x)
17 {
18     x = 0;char ch = getchar(), c = ch;
19     while(ch < '0' || ch > '9') c = ch, ch = getchar();
20     while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
21     if(c == '-') x = -x;
22 }
23 
24 const int INF = 0x3f3f3f3f;
25 const int MAXN = 2000 + 10;
26 
27 int n,sg[MAXN],b[MAXN],pow2[40];
28 
29 int main()
30 {
31     pow2[0] = 1;
32     for(register int i = 1;i <= 30;++ i) pow2[i] = pow2[i - 1] << 1;
33     for(register int i = 1;i <= MAXN;++ i)
34     {
35         memset(b, 0, sizeof(b));
36         for(register int j = 0;i - pow2[j] >= 0;++ j) b[sg[i - pow2[j]]] = 1;
37         for(register int j = 0;j <= MAXN;++ j)
38             if(!b[j]) 
39             {
40                 sg[i] = j; 
41                 break;
42             }
43     }
44     while(scanf("%d", &n) != EOF)
45     {
46         if(sg[n]) printf("Kiki
");
47         else printf("Cici
");
48     }
49     return 0;
50 } 
HDU1847
原文地址:https://www.cnblogs.com/huibixiaoxing/p/8308765.html