题意:给定n张牌,两个人轮流摸牌,每次摸牌张数为2的幂次,问先手胜还是后手胜 n≤1000
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1847
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring> 6 #include<vector> 7 8 using namespace std; 9 10 const int MAXN = 2333; 11 int n, _; 12 int f[MAXN]; 13 int sg[MAXN]; 14 bool tf[MAXN]; 15 16 int get_() { 17 f[0] = 1; 18 int i; 19 for (i = 1; f[i - 1] <= 1100 ; ++i) { 20 f[i] = f[i - 1] * 2; 21 } 22 return i - 1; 23 } 24 25 void get_sg() { 26 sg[0] = 0; 27 for (int i = 1; i <= 1100; ++i) { 28 for (int j = 0; j <= 1100; ++j) tf[j] = 1; 29 for (int j = 0; j <= 1100 && f[j] <= i; ++j) tf[sg[i - f[j]]] = 0; 30 int j = 0; 31 while (!tf[j]) ++j; 32 sg[i] = j; 33 } 34 } 35 36 int main() { 37 _ = get_(); 38 get_sg(); 39 while (scanf("%d", &n) != EOF) { 40 if (sg[n] > 0) cout << "Kiki\n"; else cout << "Cici\n"; 41 } 42 return 0; 43 }