hdu 3032 Nim or not Nim? 博弈论
这题是Lasker’s Nim.
Clearly the Sprague-Grundy function for the one-pile game satisfies g(0) = 0 and g(1) = 1. The followers of 2 are 0, 1 and (1,1), with respective Sprague-Grundy values of 0, 1, and 1⊕1 = 0. Hence, g(2) = 2. The followers of 3 are 0, 1, 2, and (1,2), with Sprague-Grundy values 0, 1, 2, and 1⊕2 = 3. Hence, g(3) = 4.
Continuing in this manner, we see
x 0 1 2 3 4 5 6 7 8 9 10 11 12...
g(x) 0 1 2 4 3 5 6 8 7 9 10 12 11...
We therefore conjecture that g(4k + 1) = 4k + 1,g(4k + 2) = 4k + 2,g(4k + 3) = 4k +4 and g(4k + 4) = 4k + 3, for all k ≥ 0.
代码如下:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#define in(x) scanf("%d",&x)
using namespace std;
int main(){
int n,t,ans,k;
in(t);
while(t--){
in(n);
ans=;
for(int i=;i<n;i++){
in(k);
if(k%==) ans^=k-;
else if(k%==) ans^=k+;
else ans^=k;
}
puts(ans?"Alice":"Bob");
}
return ;
}
hdu 3032 Nim or not Nim? 博弈论的更多相关文章
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- hdu 3032 Nim or not Nim? sg函数 难度:0
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 3032 Nim or not Nim? (sg函数求解)
Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players ...
- 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)T ...
- 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)T ...
- HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 【HDU3032】Nim or not Nim?(博弈论)
[HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio& ...
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
随机推荐
- 免费主机kilu使用
我也是看了这篇文章:http://www.cnblogs.com/tenny/archive/2011/03/30/1999957.html 采取申请注册. 主机申请地址:http://www.kil ...
- C# 高精度加法 支持小数(待优化)
直接上代码 实现思路: 1.首先小数点补 位,9223372036854775808.9+9223372036854775808.9223372036854775808 => 922337203 ...
- 关于ThinkRock中的Topics
thinkrock是一款非常优秀的思想管理软件 主题是用来分类思想的,从而将思想具体化 比如:个人,书籍,小孩等等 在其中红色以及灰色是不推荐使用的,因为有别的意思.
- (转)Spark安装与学习
摘要:Spark是继Hadoop之后的新一代大数据分布式处理框架,由UC Berkeley的Matei Zaharia主导开发.我只能说是神一样的人物造就的神器,详情请猛击http://www.spa ...
- (转)SQLSERVER表分区的介绍(一)
下面进入正题吧,很多时候当单张数据表的数据量比较大的时候比如千万级别条记录.上亿级别记录,如果不做优化,那么查询的效率大家清楚. 有经验的人会通过各种手段做优化,其中表分区就是其中一种手段. 个人对表 ...
- Windows7下安装搭建play框架
作者:Sungeek 出处:http://www.cnblogs.com/Sungeek/ 欢迎转载,也请保留这段声明.谢谢! 1.首先官网下载play的解压包 https://playframewo ...
- CAF(C++ actor framework)使用随笔(unbecome与keep_behavior用法)
看usermanual(使用随笔一里面有)看到差不多一半的时候,这个keep_behavior与unbeacome的结合引起了我的注意.(这是为什么呢?) 因为它的示例代码写的太简单了!我真的没看太懂 ...
- Spring MVC Controller中GET方式传过来的中文参数会乱码的问题
Spring MVC controller 这样写法通常意味着访问该请求,GET和POST请求都行,可是经常会遇到,如果碰到参数是中文的,post请求可以,get请求过来就是乱码.如果强行对参数进行了 ...
- bootstrap-validator使用
bootstrap-validator是一款与bootstrap相结合的表单前端验证模块,官方网址:http://1000hz.github.io/bootstrap-validator/ 下面内容大 ...
- ie支持CSS3标签
让IE6/IE7/IE8浏览器支持CSS3属性 by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/w ...