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)
Total Submission(s): 2513 Accepted Submission(s): 1300
Problem Description
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.
Input
Output
Sample Input
3
2 2 3
2
3 3
Sample Output
Bob
分析
打表找规律。
$$
sg(x)=
\begin{cases}
x-1,&x\ mod\ 4=0\\
x+1,&x\ mod\ 4=3\\
x,&else \\
\end{cases}
$$
code
#include<cstdio>
#include<algorithm> using namespace std; int get_SG(int x) {
if (x%==) return x-;
else if (x%==) return x+;
return x;
}
int main () {
int T,n,ans;
scanf("%d",&T);
for (int Case=; Case<=T; ++Case) {
scanf("%d",&n);
ans = ;
for (int t,i=; i<=n; ++i) {
scanf("%d",&t);
ans ^= get_SG(t);
}
if (ans==) puts("Bob");
else puts("Alice"); }
return ;
}
打表代码
#include<cstdio>
#include<algorithm>
#include<cstring> using namespace std; int sg[];
bool Hash[];
const int N = ; void get_SG() {
for (int i=; i<=N; ++i) {
memset(Hash,false,sizeof(Hash));
for (int j=; j<=i; ++j) {
Hash[sg[j]] = true; // 取石子
if (j!= && j!=N) Hash[sg[j]^sg[i-j]] = true; //拆分
}
for (int j=; ; ++j)
if (!Hash[j]) {sg[i] = j;break;};
}
} int main () {
get_SG();
/*for (int i=1; i<=10; ++i) {
for (int j=1; j<=10; ++j) {
printf("%d ",sg[(i-1)*10+j]);
}
puts("");
}*/
for (int i=; i<=; ++i) {
printf("%d ",sg[i]);
if (i % == ) puts("");
}
return ;
}
HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)的更多相关文章
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- 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 4919 Exclusive or (数论 or 打表找规律)
Exclusive or 题目链接: http://acm.hust.edu.cn/vjudge/contest/121336#problem/J Description Given n, find ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- HDU 4588 Count The Carries 数位DP || 打表找规律
2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5795 A Simple Nim (博弈 打表找规律)
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu_5795_A Simple Nim(打表找规律的博弈)
题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...
随机推荐
- Sometimes it takes going through something so awful to realize the beauty that is out there in this world.
Sometimes it takes going through something so awful to realize the beauty that is out there in this ...
- Ubuntu 12.04搭建svn服务器【转】
这是一个比较老旧的话题,毕竟大家现在都使用Git(http://git-scm.com/),Git在分支.代码存储.冲突.速度方面的机制都更优秀. 那我们难道还有使用svn的场景?当然,比如对Git很 ...
- [转]Jetson TX1 开发教程(1)配置与刷机
开箱 Jetson TX1是英伟达公司新出的GPU开发板,拥有世界上先进的嵌入式视觉计算系统,提供高性能.新技术和极佳的开发平台.在进行配置和刷机工作之前,先来一张全家福: 可以看到,Jetson T ...
- Android 浮动按钮的伸缩效果
在做项目时想增加点动感,于是就有如下效果: 实现起来也很简单,通过属性动画和recyclerview 滑动结合就很好实现了. 通过给recycleview添加一个滑动监听:通过滚动的差值来处理动画 m ...
- OSS基本概念介绍
存储空间(Bucket): 存储空间是用于存储对象(Object)的容器,所有的对象都必须隶属于某个存储空间. 可以设置和修改存储空间属性用来控制地域.访问权限.生命周期等,这些属性设置直接作用于该存 ...
- 域名设置A记录或CNAME记录,但无法被解析,可能是因为状态为:clientHold
解决方案: 访问https://whois.aliyun.com/查询域名状态是否为“注册商禁止解析”: 若是,联系注册商根据对方要求进行操作以便解除. https://icann.org/epp#c ...
- postman传递参数的问题
postman是一款通过post或者get发送请求测试代码的工具 如果是类的话,就选择JSON格式,如果是一个字段的方法,就直接写入方法值就好了比如 public PageResult<Info ...
- 删除临时文件的bat文件
@echo offecho 正在清除系统垃圾文件,请稍等......del /f /s /q %systemdrive%\*.tmpdel /f /s /q %systemdrive%\*._mpde ...
- CentOS系统下安装Redis
1. 安装C语言环境 yum install gcc-c++ 2.下载Redis安装包 http://download.redis.io/releases/redis-3.2.9.tar.gz 3.解 ...
- mysql添加、移除服务
sc delete 服务名 路径/bin/mysqld --install 服务名