hdu-1944&& 1534 S-Nim
2014-06-02 10:49
316 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1944
题意:在普通的Nim游戏上加入一些限制。给定一个集合S, 每次只能取S的元素个石子。
题解:SG函数。
题意:在普通的Nim游戏上加入一些限制。给定一个集合S, 每次只能取S的元素个石子。
题解:SG函数。
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 100 + 10; int sg[10000+10], a[maxn], k; int mex(int n) { bool vis[maxn] = {false}; for(int i=0; i<k; i++) { int t = n - a[i]; if(t < 0) continue; if(sg[t] == -1) sg[t] = mex(t); vis[sg[t]] = true; } for(int i=0; ; i++) if(!vis[i]) return i; } int main() { int m; while(cin >> k && k) { string s; for(int i=0; i<k; i++) cin >> a[i]; cin >> m; memset(sg, -1, sizeof(sg)); while(m--) { int j, ans = 0, hi; cin >> j; while(j--) { cin >> hi; ans ^= mex(hi); } if(ans) s += 'W'; else s += 'L'; } cout << s << endl; } return 0; }
相关文章推荐
- hdu1536 & 1944 S-NIM 博弈 SG函数
- hdu 1536 &&hdu1944 S-Nim (sg函数打表)
- HDU 1536 && HDU 1944 S-Nim (Nim博弈、SG函数模板)
- hdu 1536/1944 / POJ 2960 / ZOJ 3084 S-Nim 博弈论
- hdu1536 hdu1944 S-Nim
- 博弈论 (Nim 博弈)—— HDU 1907 && HDU 2509
- hdu 1536/ hdu 1944 S-Nim(sg函数)
- hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)
- HDU 1536 与 1944 S-Nim
- HDU 2509 Be the Winner && HDU 1907 John (Nim博弈变形)
- hdu 1907 && hdu 2509(Nim博弈)
- HDU-1536-S-Nim && HDU-1944
- hdu 1536 | hdu 1944 - S-Nim(博弈-SG)
- poj 3975&&hdu 1850 (nim)
- Hdu 1907 && Hdu2509 (nim博弈的相反胜况)
- HDU 1536 & 1944
- hdu 2509 Be the Winner(博弈Nim)
- ACM-SG函数之S-Nim——hdu1536 hdu1944 poj2960
- hdu 1536&&1944 S-Nim sg函数 难度:0
- hdu 1944 S-Nim(博弈论-求SG函数)