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 ...
随机推荐
- Oracle中存储过程传入表名学习
Oracle中存储过程传入表名: 一.动态清除该表的数据 create or replace procedure p_deletetable(i_tableName in varchar2) as ...
- Illegal pattern character 'i' 解决问题
java.lang.IllegalArgumentException: Illegal pattern character 'i' at java.text.SimpleDateFormat.comp ...
- (POJ 3694) Network 求桥个数
题目链接:http://poj.org/problem?id=3694Description A network administrator manages a large network. The ...
- linux 定时任务 crontab
为当前用户创建cron服务 1. 键入 crontab -e 编辑crontab服务文件 例如 文件内容如下: */2 * * * * /bin/sh /home/admin/jiaoben/bu ...
- CCNA第三讲笔记
TCP/IP可以分为四层或者五层 应用层.传输层.网络层.网络接口层 或者 应用层.传输层.网络层.数据链路层.物理层 与OSI相比 相同点:都有层次结构 不同点:TCP/IP的应用层包含了OSI的应 ...
- DWZ 刷新 dialog
DWZ刷新dialog: 1,在删除按钮上添加callback属性;如:(callback="dialogAjax") <a class="delImg" ...
- JS 正则 获取URL参数
function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...
- [DevExpress]RepositoryItemComboBox 数据绑定
关键代码: public static void Bind<T>(this RepositoryItemComboBox combox, ICollection source) { /*说 ...
- 为云饰数据库添加Index
Asset Collection: 1. _id_ 2. CategoryId_1_Date_-1 3. CategoryId_1_Id_1 4. CategoryId_1_Name_1 5. Cat ...
- C++ 关联容器详解——从内部结构到应用
关联容器不同于顺序容器的是:顺序容器底层用数组实现,为线性结构:关联容器在实现中,用到的非线性存储方式: 顺序容器是通过元素在容器中的位置顺序存储和访问元素,而关联容器是通过键(key)存储和读取元素 ...