注意SG函数的定义
注意最后ans!=0的判定
#include <cstdio>
#include <cstring>
int sg[210],q[210],top,ln;
char s[210];
bool b[210];
int get_sg(int x)
{
memset(b,false,sizeof(b));
for(int i=3;i<=5;i++)
if(x>=i)
b[sg[x-i]]=true;
for(int i=1;i<=x-5;i++)
b[sg[i]^sg[x-5-i]]=true;
for(int i=0;i<=200;i++)
if(!b[i])
return i;
}
char tmp[210];
bool ok(int now)
{
if(s[now]=='X') return false;
for(int i=1;i<=ln;i++) tmp[i]=s[i];
tmp[now]='X';
for(int i=1;i+2<=ln;i++)
if(tmp[i]=='X'&&tmp[i+1]=='X'&&tmp[i+2]=='X')
return true;
for(int i=1;i<=ln;i++)
{
if(i+1<=ln&&tmp[i]=='X'&&tmp[i+1]=='X') return false;
if(i+2<=ln&&tmp[i]=='X'&&tmp[i+2]=='X') return false;
}
for(int i=1;i<=ln;i++)
if(tmp[i]=='X')
for(int j=-2;j<=2;j++)
if(i+j>=1&&i+j<=ln&&tmp[i+j]!='X')
tmp[i+j]='*';
int ans=0,last=1,r;
while(last<=ln)
{
while(tmp[last]!='.'&&last<=ln) last++;
r=last;
while(tmp[r+1]=='.'&&r+1<=ln) r++;
if(last>ln||r>ln) break;
ans^=sg[r-last+1];
last=r+1;
}
if(ans==0) return true;
return false;
}
int main()
{
sg[0]=0,sg[1]=1,sg[2]=1,sg[3]=1;
for(int i=4;i<=200;i++) sg[i]=get_sg(i);
int T;scanf("%d",&T);
while(T--)
{
scanf("%s",s+1);
ln=strlen(s+1);
top=0;
for(int i=1;i<=ln;i++) if(ok(i)==true) q[++top]=i;
if(top==0) printf("LOSING\n\n");
else
{
printf("WINNING\n");
for(int i=1;i<top;i++)
printf("%d ",q[i]);
printf("%d \n",q[top]);
}
}
return 0;
}