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函数,现在我们只能通过找规律的办 ...
随机推荐
- 【MySQL】Linux下MySQL 5.5、5.6和5.7的RPM、二进制和源码安装
[MySQL]Linux下MySQL 5.5.5.6和5.7的RPM.二进制和源码安装 1.1 BLOG文档结构图 1.2 前言部分 1.2.1 导读和注意事项 各位技术爱好者,看完本文后, ...
- 7.31.2 this关键字
this用在所有方法中: 用来区分局部变量和成员变量的名字二义性! 如:在set方法中这样写:name = name; 则java会遵循"谁近谁优先"的规则,会给局部变量赋值 ...
- mysql 常用函数总结
常用处理函数: mysql_connect(server,user,pwd,newlink,clientflag) 连接服务器的函数,成功则返回MySQL标识,失败则返回FALSE mysql_sel ...
- KVM套件-linux基础
KVM套件 使用KVM的虚拟机,通过KVM的虚拟机克隆功能,提高效率,避免在实验过程中重装系统. 另外,在LINUX系统上使用KVM的虚拟化,可以获得更好性能,且可以提前熟悉企业级虚拟化技术. 过程: ...
- Pyinstaller(python打包为exe文件)
需求分析: python脚本如果在没有安装python的机器上不能运行,所以将脚本打包成exe文件,降低脚本对环境的依赖性,同时运行更加迅速. 当然打包的脚本似乎不是在所有的win平台下都能使用, ...
- 挖个坑,写一个Spring+SpringMVC+Mybatis的项目
想挖个坑督促自己练技术,有时候想到一个项目,大概想了一些要实现的功能,怎么实现.现在觉得自己差不多能完成QQ空间的主要功能了.准备立个牌坊,写一个类似功能的网站.并且把进度放到这里来. 初步计划实现以 ...
- java值传递与引用传递实例
public class Test2 { public static void main(String[] args) { int[] arr=new int[5]; arr[0]=10; arr[1 ...
- kappa系数在评测中的应用
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/7091315.html 前言 最近打算把翻译质量的人工评测好 ...
- Python学习日志_2017/09/08
今天早晨学习了<Head First :HTML and CSS>:学习了两个章节,感觉从基础学习特别的踏实,能看懂的同时踏踏实实的锻炼了基础的能力.我个人认为无论哪个行业,最重要的永远是 ...
- 深入理解JAVA I/O系列六:Linux中的IO模型(转载的文章非常值得学习)
From:http://www.cnblogs.com/dongguacai/p/5770287.html IO模型 linux系统IO分为内核准备数据和将数据从内核拷贝到用户空间两个阶段. 这张图大 ...