最入门的sg,水题
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; int c[102]; int sg[10005]; int k,n; int get_sg(int now) { if(~sg[now])return sg[now]; int vis[102],i; memset(vis,0,sizeof(vis)); for(i=0;i<k;i++) { if(now<c[i])continue; vis[get_sg(now-c[i])]=1; } for(i=0;vis[i]==1;i++); return sg[now]=i; } int main() { while(~scanf("%d",&k)&&k) { int i,m; for(i=0;i<k;i++)scanf("%d",&c[i]); scanf("%d",&m); memset(sg,-1,sizeof(sg)); sg[0]=0; int ans=0,t; while(m--) { ans=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&t); ans^=get_sg(t); } putchar(ans?'W':'L'); } puts(""); } }
时间: 2024-09-20 05:16:22