SG函数应用!!
代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int sg[],a[],n;
int get_sg(int m)
{
if(sg[m]!=-) return sg[m];
bool vis[];
memset(vis,,sizeof(vis));
for(int i=;i<n&&a[i]<=m;i++)
for(int j=;j<=m-a[i]-j;j++){
vis[get_sg(m-a[i]-j)^get_sg(j)]=;
}
int i=;
while(vis[i]) i++;
return sg[m]=i;
}
int main()
{
int i,j,m,p,k;
while(scanf("%d",&n)!=EOF){
for(i=;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
for(i=j=;i<n;i++)
if(a[i]!=a[j-]){
a[j++]=a[i];
}
n=j;
scanf("%d",&m);
memset(sg,-,sizeof(sg));
sg[]=;
while(m--){
scanf("%d",&k);
puts(get_sg(k)?"":"");
}
}
return ;
}