您的位置:首页 > 其它

HDU - 1536 S-Nim SG函数

2017-10-31 21:30 337 查看
SG函数应用

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>

using namespace std;
typedef long long ll;
const int maxn = 1e4 + 7, INF = 0x7f7f7f7f, mod = 1e9 + 7;

int sg[maxn], temp = 1;
set<int> st;
int k, a[maxn], vis[maxn] = {0};

void init() {//cout << " === " << endl;
sg[0] = 0;
for(int i = 1; i <= 10000; ++i) {
temp++;
for(int j = 0; a[j] <= i && j < k; ++j) {
vis[sg[i-a[j]]] = temp;
}
for(int j = 0; j <= i; ++j)
if(vis[j
4000
] != temp) { sg[i] = j; break; }
}
}

int main() {

int T, n, x;
while(~scanf("%d", &k) && k) {
for(int i = 0; i < k; ++i)
scanf("%d", &a[i]);
sort(a, a+k);
init();
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
int ans = 0;
while(n--) {
scanf("%d", &x);
ans ^= sg[x];
}
if(ans == 0) printf("L");
else printf("W");
}
puts("");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: