HDU 3032 Nim or not Nim? Lasker's Nim
来源:互联网 发布:123 网络 编辑:程序博客网 时间:2024/06/12 00:17
题目大意:
就是现在初始有多堆石子, 每次可以将任意一堆拿走任意个或者将这一对分成两堆(不为空), 拿走最后一颗石子的人胜利
问谁会获得胜利
大致思路:
这个是Lasker's Nim 的模型, 我是打表找出SG函数的规律做的...
SG[4*k + 1] = 4*k + 1;
SG[2*k + 2] = 4*k + 2;
SG[4*k + 3] = 4*k + 4;
SG[4*k + 4] = 4*k + 3;
然后利用游戏的和将每一堆石子作为子游戏, 得到异或和判断是否为0就行了
代码如下:
Result : Accepted Memory : 1628 KB Time : 0 ms
/* * Author: Gatevin * Created Time: 2015/5/2 9:16:05 * File Name: Rin_Tohsaka.cpp */#include<iostream>#include<sstream>#include<fstream>#include<vector>#include<list>#include<deque>#include<queue>#include<stack>#include<map>#include<set>#include<bitset>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<ctime>#include<iomanip>using namespace std;const double eps(1e-8);typedef long long lint;#define foreach(e, x) for(__typeof(x.begin()) e = x.begin(); e != x.end(); ++e)#define SHOW_MEMORY(x) cout<<sizeof(x)/(1024*1024.)<<"MB"<<endl/* * SG[4*k + 1] = 4*k + 1; * SG[2*k + 2] = 4*k + 2; * SG[4*k + 3] = 4*k + 4; * SG[4*k + 4] = 4*k + 3; */int s[1000010];int main(){ int T; scanf("%d", &T); int n; while(T--) { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", s + i); for(int i = 0; i < n; i++) switch(s[i] % 4) { case 0: s[i] = s[i] - 1; break; case 1: s[i] = s[i]; break; case 2: s[i] = s[i]; break; case 3: s[i] = s[i] + 1; break; } int sg = 0; for(int i = 0; i < n; i++) sg ^= s[i]; if(sg) printf("Alice\n"); else printf("Bob\n"); } return 0;}
0 0
- HDU 3032 Nim or not Nim? Lasker's Nim
- HDOJ 3032 Nim or not Nim Lasker's Nim游戏
- Lasker's Nim (HDU 3032)
- HDU 3032 Nim or not Nim? && HDU 5795 A Simple Nim (Lasker's Nim游戏、SG函数、取走-分割游戏)
- HDU 3032 Lasker's Nim博弈
- 【HDU3032】【Lasker's Nim(一种Nim游戏)】Nim or not Nim? Multi-SG博弈、打表
- HDU 3032 Nim or not Nim?
- hdu 3032 Nim or not Nim? 博弈
- Nim or not Nim? - HDU 3032 博弈论
- HDU 3032Nim or not Nim?
- 【hdu 3032】Nim or not Nim?
- hdu 3032 Nim or not Nim?
- Nim or not Nim? HDU 3032
- HDU 3032 Nim or not Nim?
- HDU 3032Nim or not Nim Nim博弈 规律
- hdu 3032 Nim or not Nim? (SG打表找规律)
- HDU 3032 - Nim or not Nim?(SG)
- HDU 3032 Nim or not Nim? (sg函数)
- An problem about date(怎么就放在动态规划里面呢。。。)
- php嵌入js以及下拉框的显示
- Eclipse从零配置Maven环境 笔记
- 网页卷去的距离与偏移量
- _beginThreadex的用法
- HDU 3032 Nim or not Nim? Lasker's Nim
- JAVA学习第二天(1)
- Servlet&JSP的那些事儿(一)
- string的size/length、resize/reverse和capacity
- 矩阵键盘扫描程序
- IOS开发之UITextField
- Servlet&JSP的那些事儿(二)
- [BZOJ 1045] HAOI 2008 糖果传递 & [BZOJ 3293] CQOI 2011 分金币 · 数学
- java.sql.SQLException: No operations allowed after connection closed.Connection was implicitly clos