bzoj千题计划260:bzoj2940: [Poi2000]条纹
http://www.lydsy.com/JudgeOnline/problem.php?id=2940
SG
博弈入门推荐张一飞的《由感性认识到理性认识 ——透析一类搏弈游戏的解答过程》
#include<cstdio> #include<cstring> using namespace std; int a,b,c; int sg[1001]; int Sg(int n) { if(sg[n]!=-1) return sg[n]; bool vis[1001]={0}; for(int i=1;i+a-1<=n;++i) vis[Sg(i-1)^Sg(n-i-a+1)]=true; for(int i=1;i+b-1<=n;++i) vis[Sg(i-1)^Sg(n-i-b+1)]=true; for(int i=1;i+c-1<=n;++i) vis[Sg(i-1)^Sg(n-i-c+1)]=true; for(int i=0;i<=n;++i) if(!vis[i]) return sg[n]=i; } int main() { scanf("%d%d%d",&a,&b,&c); int T,n; scanf("%d",&T); memset(sg,-1,sizeof(sg)); sg[0]=0; while(T--) { scanf("%d",&n); if(Sg(n)) printf("1\n"); else printf("2\n"); } return 0; }