HDU_1536 SNim(sg函数)

  类似 Fibonacci again and again

貌似有点模板的感觉,就是不知到hash数组的上界是怎么算出来的,无语,继续研究去。。。

#include <iostream>
#include <cstdio>

using namespace std;

const int N = 10010;
const int M = 110;

int num[M];
int vis[N];
int sg[N];
int n;

void get_sg(){
int i, j;
for(i = 0; i < N; i++)
sg[i] = 0;
for(i = 1; i < N; i++){
for(j = 0; j < 1002; j++) vis[j] = 0;
for(j = 0; j < n; j++){
if(num[j] <= i){
vis[sg[i-num[j]]] = 1;
}
}
for(j = 0; j < N; j++){
if(!vis[j])
break;
}
sg[i] = j;
}
}

int main(){
//freopen("data.in", "r", stdin);

int i, m, flag, x, t;
while(scanf("%d", &n) && n){
for(i = 0; i < n; i++){
scanf("%d", &num[i]);
}
get_sg();
scanf("%d", &m);
while(m--){
flag = 0;
scanf("%d", &t);
while(t--){
scanf("%d", &x);
flag ^= sg[x];
}
if(flag) putchar('W');
else putchar('L');
}
putchar('\n');
}
}




原文地址:https://www.cnblogs.com/vongang/p/2189681.html