HDU

来源:互联网 发布:邻里中国网php面试题 编辑:程序博客网 时间:2024/06/08 13:38

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] != 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;}