标签:style class blog c code java
sg[0]=0;
sg[i]=mex{sg[i-2^(j)]} (i>=2^j)
mex()为不在此集合的最小非负整数
#include <stdio.h> #include <string.h> #include <vector> #include <algorithm> using namespace std; using namespace std; int main() { int sg[10000]; int n; int i; vector <int> nim; while (scanf("%d",&n)!=EOF) { sg[0]=0; for (i = 1; i <= n; i++) { nim.clear(); int tmp=i; int each=1; while (tmp>=each) { nim.push_back(sg[tmp-each]); each<<=1; } int x=0; sort(nim.begin(),nim.end()); for (int j=0;j<nim.size();j++) { if (nim[j]==x) x++; else { if (nim[j]>x) break; } } sg[i]=x; } if (sg[n]==0) printf("Cici\n"); else printf("Kiki\n"); } return 0; }
标签:style class blog c code java
原文地址:http://www.cnblogs.com/six-god/p/3750457.html