bzoj千题计划260:bzoj2940: [Poi2000]条纹

时间:2023-03-09 21:39:20
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[]; int Sg(int n)
{
if(sg[n]!=-) return sg[n];
bool vis[]={};
for(int i=;i+a-<=n;++i) vis[Sg(i-)^Sg(n-i-a+)]=true;
for(int i=;i+b-<=n;++i) vis[Sg(i-)^Sg(n-i-b+)]=true;
for(int i=;i+c-<=n;++i) vis[Sg(i-)^Sg(n-i-c+)]=true;
for(int i=;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,-,sizeof(sg));
sg[]=;
while(T--)
{
scanf("%d",&n);
if(Sg(n)) printf("1\n");
else printf("2\n");
}
return ;
}