HDU 3032 Nim or not Nim?(博弈,SG打表找规律)
Nim or not Nim?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 613 Accepted Submission(s): 282
Nim is usually played as a misere game, in which the player to take the last object loses. Nim can also be played as a normal play game, which means that the person who makes the last move (i.e., who takes the last object) wins. This is called normal play because most games follow this convention, even though Nim usually does not.
Alice and Bob is tired of playing Nim under the standard rule, so they make a difference by also allowing the player to separate one of the heaps into two smaller ones. That is, each turn the player may either remove any number of objects from a heap or separate a heap into two smaller ones, and the one who takes the last object wins.
3
2 2 3
2
3 3
Bob
通过SG函数打表可以发现规律。
当n=4*k时,sg[n] = n-1;
当n= 4*k+3 时,sg[n] = n+1;
其余sg[n] = n;
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
const int MAXN = ;
int SG(int x)
{
if(x == )return x;
if(x % == )return x-;
if(x % == )return x+;
return x;
}
int main()
{
int T;
int n,a;
int sum;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
sum = ;
for(int i = ;i < n;i++)
{
scanf("%d",&a);
sum ^= SG(a);
}
if(sum == )printf("Bob\n");
else printf("Alice\n");
}
return ;
}
HDU 3032 Nim or not Nim?(博弈,SG打表找规律)的更多相关文章
- hdu 2147 kiki's game(DP(SG)打表找规律)
题意: n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边. 无法移动硬币的人负. 给出n和m,问,先手胜还是后手胜. 数据范围: n, m (0<n ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- HDU 3032 (SG打表找规律)
题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围 ...
- HDU 3032 Nim or not Nim?(SG打表找规律)
题意: 给你n堆石子,你每次只能操作一堆石子 1.拿去任意个,最少1个 2.把这一堆分成两堆,没有要求对半分 解析+代码: 1 //解题思路: 2 //对于一个给定的有向无环图,定义关于图的每个顶点的 ...
- hdu 3032 sg打表找规律 *
有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...
- A Simple Nim (SG打表找规律)
题意:有n堆石子,每次可以将其中一堆分为数量不为0的3堆,或者从其中一堆中拿走若干个,最终拿完的那个人赢. 思路:直接暴力SG状态,然后找出其中的规律,异或一下每一堆的状态就可以了. #include ...
- HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)
Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
随机推荐
- [HNOI2015]部分题解
Day1 T2 [HNOI2015]接水果 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果.由于她已经DT FC 了The big black, 她觉得这个游戏太简单了, ...
- 归档普通对象Demo示例程序源代码
源代码下载链接:06-归档普通对象.zip34.2 KB // MJPerson.h // // MJPerson.h // 06-归档普通对象 // // Created by apple o ...
- set .net principle
var ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(FormsA ...
- 【Mysql优化】key和index区别
mysql的key和index多少有点令人迷惑,这实际上考察对数据库体系结构的了解的. 1).key 是数据库的物理结构,它包含两层意义,一是约束(偏重于约束和规范数据库的结构完整性),二是索引 ...
- python-列表 字典 集合 元祖 字符串的相关总结练习
1.执行python脚本的两种方式指定解释器执行在交互器中执行 2.简述位.字节的关系:ASCII1个二进制位是计算机里的最小表示单元1个字节是计算机里最小的储存单元二进制位=8bits(位)8bit ...
- ios 里如何处理四舍五入的问题
http://blog.sina.com.cn/s/blog_a2774bb10101293j.html 今天朋友问我一个问题,就是如何只舍不入.比如 float price = 0.126,怎么样才 ...
- C++高精度
整理了一下高精度,虽然可用java,但很多时候还是C++写的方便. 附上kuangbin神的高精度模板(HDU1134 求卡特兰数) #include <iostream> #includ ...
- python基础===python3中 http.client 和 urllib的那些事
import http.client #python3中没有了 httplib的库 #python 3.x中urllib库和urilib2库合并成了urllib库.. #其中urllib2.urlop ...
- [ python3 ] 基于zabbix 自动抓取每天监控数据
通过python登录到zabbix直接抓取每天的数据的图片趋势图,并制作成静态index.html给与展示并发送提示邮件. 操作系统:Centos6.7 python版本:python3.5 #!/u ...
- css的class, id等常用命名规则
CSS的class.id.css文件名的常用命名规则 (一)常用的CSS命名规则 头:header 内容:content/container 尾:footer 导航:nav 侧栏:sid ...