#include <stdio.h>
#include <string.h>
int s[110];
int sg[10010],hash[110];
int n, m;
int getsg(int x) //sg模板
{
int i;
if(sg[x] != -1)
return sg[x];
memset(hash,0,sizeof(hash));
for(i = 0; i < n; i++) //n为可以抓的个数
{
if(x >= s[i])
{
sg[x - s[i]] = getsg(x - s[i]); //s[i]为可以抓的数
hash[sg[x - s[i]]] = 1;
}
}
for(i = 0; i < 110; i++)
{
if(hash[i] == 0)
break;
}
return i;
}
int main ( )
{
int i,k;
int a,j,l;
char ans[110];
while(scanf("%d", &n) != EOF)
{
if(n == 0)
break;
k = 0;
for(i = 0; i < n; i++)
scanf("%d", &s[i]);
memset(sg, -1, sizeof(sg));
sg[0] = 0;
for(i = 1; i < 10010; i++)
sg[i] = getsg(i);
scanf("%d", &m);
for(i = 0; i < m; i++)
{
int sum = 0;
scanf("%d", &l);
for(j = 0; j < l; j++)
{
scanf("%d", &a);
sum ^= sg[a]; //尼姆的变形
}
if(sum == 0)
ans[k ++] = 'L';
else
ans[k ++] = 'W';
}
for(i = 0; i < k; i++)
printf("%c", ans[i]);
printf("\n");
}
return 0;
}
hdu 1536 S-Nim|| poj 2960 S-Nim (sg函数)
最新推荐文章于 2019-04-18 23:51:54 发布
