链接:http://acm.hdu.edu.cn/showproblem.php?pid=1536
题意:给定k个数s[1]~s[k],再给定多组数据,每组数据给定n个数字表示有n个正数a[1]~a[n],玩家每次可以从某一堆里减去一个s[j]。无法操作就输了。
分析:博弈中SG函数的经典应用。
代码:
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=10010;
const int MAX=1000000100;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
typedef double db;
typedef unsigned long long ull;
int k,a[105],q[105],f[N];
void deal(int n) {
int i,j;
f[0]=q[100]=0;
for (i=1;i<=n;i++) {
for (j=0;j<100;j++) q[j]=0;
for (j=1;j<=k;j++)
if (i-a[j]>=0) q[f[i-a[j]]]=1;
else break ;
for (j=0;j<=100;j++)
if (!q[j]) { f[i]=j;break ; }
}
}
int main()
{
int i,j,n,m,x,xo;
while (scanf("%d", &k)&&k) {
for (i=1;i<=k;i++) scanf("%d", &a[i]);
sort(a+1,a+k+1);deal(10000);
scanf("%d", &n);
for (i=1;i<=n;i++) {
scanf("%d", &m);xo=0;
for (j=1;j<=m;j++) {
scanf("%d", &x);xo^=f[x];
}
if (!xo) printf("L");
else printf("W");
}
printf("\n");
}
return 0;
}