HDU 3032 Nim or not Nim(SG函数打表找规律)
来源:互联网 发布:网络上gm是什么意思啊 编辑:程序博客网 时间:2024/05/16 10:06
解题思路:
通过打表发现,当x % 4 == 0 的时候SG值为x - 1,当x % 4 == 3的时候SG值为x + 1,其他时候SG值为x;
//AC代码#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <vector>#include <map>#include <set>#include <algorithm>using namespace std;const int MAXN = 1000 + 10;int main(){ int T; scanf("%d", &T); while(T--) { int n, x; scanf("%d", &n); int ans = 0; for(int i=0;i<n;i++) { scanf("%d", &x); if(x % 4 == 0) ans ^= (x - 1); else if(x % 4 == 3) ans ^= (x +1); else ans ^= (x); } if(ans) printf("Alice\n"); else printf("Bob\n"); } return 0;}
//打表代码#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <vector>#include <map>#include <set>#include <algorithm>using namespace std;const int MAXN = 1000 + 10;int vis[MAXN];int SG[MAXN];int mex(int x){ if(SG[x] != -1) return SG[x]; memset(vis, 0, sizeof(vis)); for(int i=1;i<=x/2;i++) vis[mex(i) ^ mex(x-i)] = 1; for(int i=1;i<=x;i++) vis[mex(x-i)] = 1; for(int i=0;;i++) if(!vis[i]) { SG[x] = i; break; } return SG[x];}int main(){ memset(SG, -1, sizeof(SG)); for(int i=0;i<100;i++) SG[i] = mex(i); for(int i=0;i<100;i++) { printf("%d %d\n", i, SG[i]); } return 0;}
0 0
- 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 SG函数入门+打表找规律
- HDU 3032 Nim or not Nim? (sg函数求解)
- HDU 3032 Nim or not Nim? (SG函数应用)
- hdu 3032 Nim or not Nim? (Multi-SG函数)
- HDU 3032 Nim or not Nim?(博弈 SG打表找规律)
- HDU 3032.Nim or not Nim?【SG函数打表找规律】【4月11】
- 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 2311-Nim or not Nim?(Nim博弈-打sg表找规律)
- HDU 3032 - Nim or not Nim?(SG)
- HDU 3032 Nim or not Nim?(博弈 sg表)
- SG函数找规律练习-HDU3032- Nim or not Nim?
- Full Binary Tree(GCJ2014 round1A PB)
- Delphi的三层开发初学经验
- hadoop tasktracker 异常:PriviledgedActionException as:adlog cause:ENOENT: No such file or directory
- IOS常用正则表达式
- DOORS输出database的目录树
- HDU 3032 Nim or not Nim(SG函数打表找规律)
- 单张图片人脸检测
- myeclipse8.6导入jdk1.8的项目后出现的问题
- sql sever 创建带条件的唯一性索引
- 【转载】java拾遗
- salesforce 访问权限控制以及和java的区别
- 在Android中查看和管理sqlite数据库
- Delphi三层实例
- 【C语言】[笔试题]:常见笔试题