HDU-3032
Problem Description
Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap. 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
Input contains multiple test cases. The first line is an integer ≤ T ≤ , the number of test cases. Each case begins with an integer N, indicating the number of the heaps, the next line contains N integers s[], s[], ...., s[N-], representing heaps with s[], s[], ..., s[N-] objects respectively.( ≤ N ≤ ^, ≤ S[i] ≤ ^ - ) Output
For each test case, output a line which contains either "Alice" or "Bob", which is the winner of this game. Alice will play first. You may asume they never make mistakes. Sample Input Sample Output
Alice
Bob
Nim or not Nim?
题目就不说了,解题思路就是SG先打表找规律,简单的尼姆博奕
打表代码 :
#include <cstdio>
#include <cstring> #define maxn 1000005 int sg[maxn];
bool vis[maxn]; void GetSG()
{
for(int i = ; i <= ; i++)
{
memset(vis , , sizeof(vis));
for(int j = ; j < i ; j++)
vis[sg[j]] = ;
if(i >= )
{
for(int j = ; j < i ; j++)
vis[ sg[j] ^ sg[i-j] ] = ;
}
int mid = ;
while(vis[mid])
mid++;
sg[i] = mid;
printf("%d : %d\n",i,sg[i]);
}
} int main()
{
GetSG();
return ; }
打表结果 :
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
Result
由于是刚开始接触这种类型的尼姆博弈,说实话对SG还不是很理解,还不能灵活的应用,所以这篇随笔目前也没啥注释,
待我对这类问题有了更清楚的理解,再回来看看这吧。
AC Code :
#include <bits/stdc++.h> int GetSG(int num)
{
if( == num % )
return num - ;
if( == num % )
return num + ;
return num;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n , res = , num;
scanf("%d",&n);
for(int i = ; i <= n ; i++)
{
scanf("%d" , &num);
res ^= GetSG(num);
}
if(res)
printf("Alice\n");
else
printf("Bob\n");
}
return ;
}
其实这个题和 HDU-5795 http://acm.split.hdu.edu.cn/showproblem.php?pid=5795 神似,(同样的多校赛的题,年份不一样//滑稽)不过就是那个题可以分为3个更小的堆(其实我是先做那个题才做这个的),同样打表找规律,代码稍微修改下就能过,这里就不多说了。
HDU-3032的更多相关文章
- 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 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
- 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?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
- HDU 3032 Nim or not Nim (sg函数)
加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...
- HDU 3032 Nim or not Nim?(sg函数)
题目链接 暴力出来,竟然眼花了以为sg(i) = i啊....看表要认真啊!!! #include <cstdio> #include <cstring> #include & ...
- hdu 3032 sg打表找规律 *
有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...
- hdu 3032 Nim or not Nim?(搜索打SG表)
题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) , 也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范 ...
- HDU 3032 (Nim博弈变形) Nim or not Nim?
博弈的题目,打表找规律还是相当有用的一个技巧. 这个游戏在原始的Nim游戏基础上又新加了一个操作,就是游戏者可以将一堆分成两堆. 这个SG函数值是多少并不明显,还是用记忆化搜索的方式打个表,规律就相当 ...
- hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...
随机推荐
- 当使用composer安装组件时提示错误
这种情况可以重装一下fxp/composer-asset-plugin 具体命令: php composer.phar global require "fxp/composer-asset- ...
- pwnable.kr brainfuck之write up
I made a simple brain-fuck language emulation program written in C. The [ ] commands are not impleme ...
- TIKV副本一致性检查机制分析
背景 TIKV使用raft协议来实现副本同步,任何时刻写入一个KEY-VAL键值对,都会基于RAFT协议复制到不同机器的三个副本上,raft协议本身能保证副本同步的强一致性,但是任何系统都可能存在BU ...
- opencv VideoCapture使用示例
在centos7下验证VideoCapture功能. 1 opencv处理视频时要使用ffmpeg,这里使用添加源的方式安装,分为3步 1.1 先安装EPEL Release,使用其他的repo源,所 ...
- Sublime Text3自定义代码片段
1.打开工具--插件开发--新建代码片段 会出现下图: 2.在<![CDATA[和]]>内写下你要的代码片段,注意的是代码片段要靠最左边. 3.设置快捷键,把下面tabTrigger标签的 ...
- Linux Command Line learning
https://www.codecademy.com/en/courses/learn-the-command-line Background The command line is a text i ...
- 网络协议TFTP
TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户端与服务器之间进行简单文件传输的协议.和使用TCP的文件传输协议(FTP ...
- 关于Java的发展前景
各位看官觉得Java还能火几年?未来的发展方向是什么?
- github+hexo搭建自己的博客网站(六)进阶配置(搜索引擎收录,优化你的url)
详细的可以查看hexo博客的演示:https://saucxs.github.io/ 绑定了域名: http://www.chengxinsong.cn hexo+github博客网站源码(可以clo ...
- 使用SVG基本操作API
前面的话 本文将详细介绍SVG基本操作API,并使用这些API操作实例效果 基础API 在javascript中,可以使用一些基本的API来对SVG进行操作 [NS地址] 因为SVG定义在其自身的命令 ...