| Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
2 2 5 3 2 5 12 3 2 4 7 4 2 3 7 12 5 1 2 3 4 5 3 2 5 12 3 2 4 7 4 2 3 7 12 0
Sample Output
LWW WWL
Source
SG函数入门题。。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int s[110],n,mm,m,sg[11000];
void get_SG()
{
memset(sg,0,sizeof(sg));
bool vis[11000];
for(int x=1;x<=10000;x++)
{
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
if(s[i]>x) break;
vis[sg[x-s[i]]]=1;
}
for(int i=0;i<=10000;i++)
{
if(!vis[i])
{
sg[x]=i;
break;
}
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=0;i<n;i++) scanf("%d",s+i);
sort(s,s+n);
get_SG();
scanf("%d",&mm);
while(mm--)
{
scanf("%d",&m);
int ANS=0;
while(m--)
{
int a;
scanf("%d",&a);
ANS^=sg[a];
}
if(ANS) putchar(‘W‘);
else putchar(‘L‘);
}
putchar(10);
}
return 0;
}
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int s[110],n,mm,m,sg[11000];
int SG_dfs(int x)
{
if(sg[x]!=-1) return sg[x];
bool vis[110];
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
if(x-s[i]>=0)
{
vis[SG_dfs(x-s[i])]=1;
}
else break;
}
for(int i=0;i<=10000;i++)
{
if(!vis[i])
{
sg[x]=i;
break;
}
}
return sg[x];
}
int main()
{
while(scanf("%d",&n)!=EOF&&n)
{
memset(sg,-1,sizeof(sg));
for(int i=0;i<n;i++) scanf("%d",s+i);
sort(s,s+n);
scanf("%d",&mm);
while(mm--)
{
scanf("%d",&m);
int ANS=0;
while(m--)
{
int a;
scanf("%d",&a);
ANS^=SG_dfs(a);
}
if(ANS) putchar(‘W‘);
else putchar(‘L‘);
}
putchar(10);
}
return 0;
}
原文:http://blog.csdn.net/u012797220/article/details/19816483