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;
}
#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;
}
相关文章推荐
- HDU 1536 S-Nim SG函数
- HDU - 1536 S-Nim SG函数
- HDU 1536 S-Nim SG函数 Nim
- HDU 1536 && POJ 2960 S-Nim SG函数
- hdu 1536&&1944 S-Nim sg函数 难度:0
- hdu 1536 S-Nim (简单sg函数)
- hdu 1536 S-Nim(SG函数)
- HDU 1536 S-Nim(博弈论)
- HDU 1536 S-Nim(博弈论)
- hdu 1536/ hdu 1944 S-Nim(sg函数)
- HDU1536 SG博弈+尼姆博弈
- HDU 1536
- hdu 1536 S-Nim(SG函数)
- 博弈 hdu 1536 SG函数解法
- hdu_1536_S-Nim(DFS_SG博弈)
- hdu 1536、hdu 1944 S-Nim(博弈SG函数)
- hdu 1536 SG函数模板题 千万注意游戏的组合用SG函数值异或 是SG函数的值啊
- poj 2960,hdu 1536 S-NIM 博弈
- hdu 1536 S-Nim(SG函数)
- HDU 1536 S-Nim 博弈求sg函数