【POJ】【2960】S-Nim
博弈论
这题跟 BZOJ 1874 取石子游戏 差不多
先暴力求出10000以内的SG函数(利用定义来求即可)
然后每次询问直接将SG值异或起来即可……
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 Source Code 2 Problem: 2960 User: sdfzyhy 3 Memory: 444K Time: 313MS 4 Language: G++ Result: Accepted 5 6 Source Code 7 8 //POJ 2960 9 #include<cstdio> 10 #include<cstring> 11 #define F(i,j,n) for(int i=j;i<=n;++i) 12 int getint(){ 13 int v=0,sign=1; char ch=getchar(); 14 while(ch<'0'||ch>'9'){ if (ch=='-') sign=-1; ch=getchar();} 15 while(ch>='0'&&ch<='9'){ v=v*10+ch-'0'; ch=getchar();} 16 return v*=sign; 17 } 18 const int N=10010; 19 /******************tamplate*********************/ 20 int f[N],s[101]; 21 bool mark[N]; 22 void calsg(int n){ 23 f[0]=0; 24 F(i,1,10000){ 25 memset(mark,0,sizeof mark); 26 F(j,1,n) if (i-s[j]>=0) 27 mark[f[i-s[j]]]=1; 28 F(j,0,i) if(!mark[j]){ f[i]=j;break;} 29 } 30 } 31 int main(){ 32 int n,m,k; 33 while(scanf("%d",&n)!=EOF && n){ 34 F(i,1,n) s[i]=getint(); 35 m=getint(); 36 calsg(n); 37 F(i,1,m){ 38 k=getint(); 39 int ans=0; 40 F(j,1,k) ans^=f[getint()]; 41 printf(ans ? "W" : "L"); 42 } 43 printf("\n"); 44 } 45 return 0; 46 }