HDU3032 Nim or not Nim
2012-07-29 22:31
274 查看
/* *State: *题目大意: * Alice和Bob轮流取N堆石子,每堆S[i]个,Alice先, * 每一次可以从任意一堆中拿走任意个石子,也可以将 * 一堆石子分为两个小堆。先拿完者获胜。(1 ≤ N ≤ 10^6, * 1 ≤ S[i] ≤ 2^31 - 1) *解题思路: * 找sg规律。 *解题感想: * 一看数据规模就知道sg不靠谱,应该是规律型的。 * 自己用笔模拟了大半天,模拟得蛋疼了之后干脆写成 * 代码吧,结果计算机一算就是靠谱些(用笔还模拟错了, * 怪不得一开始没有找对规律),计算机是个好东西啊。 */ //下面这一段用来打表找规律的。 //前三十组的sg值,很容易找出规律 /* sg[0]: 0 sg[1]: 1 sg[2]: 2 sg[3]: 4 sg[4]: 3 sg[5]: 5 sg[6]: 6 sg[7]: 8 sg[8]: 7 sg[9]: 9 sg[10]: 10 sg[11]: 12 sg[12]: 11 sg[13]: 13 sg[14]: 14 sg[15]: 16 sg[16]: 15 sg[17]: 17 sg[18]: 18 sg[19]: 20 sg[20]: 19 sg[21]: 21 sg[22]: 22 sg[23]: 24 sg[24]: 23 sg[25]: 25 sg[26]: 26 sg[27]: 28 sg[28]: 27 sg[29]: 29 */
打表代码:
View Code
#include <iostream> using namespace std; int get_sg(int n) { if(n == 0) return 0; int remain = n % 4; if(remain == 0) return n - 1; else if(remain == 3) return n + 1; else return n; } int main(void) { int cas; scanf("%d", &cas); while(cas--) { int n, yihuo = 0; scanf("%d", &n); for(int i = 0; i < n; i++) { int pile, tmp; scanf("%d", &pile); tmp = get_sg(pile); yihuo ^= tmp; } if(!yihuo) printf("Bob\n"); else printf("Alice\n"); } return 0; }
相关文章推荐
- 【HDU3032】【Lasker's Nim(一种Nim游戏)】Nim or not Nim? Multi-SG博弈、打表
- HDU3032 Nim or not Nim? 博弈
- [HDU3032]Nim or not Nim?(博弈Multi-SG游戏)
- HDU3032-Nim or not Nim?
- hdu3032 Nim or not Nim?(SG函数)
- HDU3032 Nim or not Nim?(SG函数)
- SG函数找规律练习-HDU3032- Nim or not Nim?
- hdu3032 Nim or not Nim?
- SG函数找规律练习-HDU3032- Nim or not Nim?
- Nim or not Nim? - HDU 3032 博弈论
- HDOJ 3032 Nim or not Nim? (博弈 :SG)
- 博弈 HDU - Nim or not Nim?
- HDOJ 3032 Nim or not Nim?
- HDU 3032 Nim or not Nim? SG打表找规律
- hdu 3032 Nim or not Nim? (SG函数+打表)
- HDU 3032 Nim or not Nim? (需求的游戏SG功能)
- hdu 3032 Nim or not Nim? (SG函数+打表)
- HDU 3032 Nim or not Nim?(分成两堆或取)
- hdu 3032 Nim or not Nim? 博弈(SG定理+找规律)
- HOJ2838 Nim or not Nim?