hdu 3032 Nim or not Nim?(搜索打SG表)
题意:
有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,
也可以选择将这堆石子分成任意的两堆。alice与bob轮流取,取走最后一个石子的人胜利。
思路:
因为数的范围比较大,所以最好通过SG打表的结果找出规律在解。
打表代码
#include<cstdio>
#include<cstring>
int sg[];
int find(int x)
{
if(sg[x]>=) return sg[x];
bool mex[]= {};
for(int i=; i<x; i++)
{
mex[find(i)]=;//
if(x-i>&&i>) mex[find(i)^find(x-i)]=;
}
int i=;
while(mex[i]) i++;
return sg[x]=i;
}
int main()
{
int n;
memset(sg,-,sizeof(sg));//sg[0]=0;
//printf("%d#",sg[0]);
find();
for(int i=; i<=; i++) printf("%d %d\n",i,sg[i]);
return ;
}
提交代码:
#include<stdio.h>
int x[]={-,,,};
int main()
{
int _case,n,m,ans;
scanf("%d",&_case);
while(_case--)
{
ans=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&m);
ans^=m+x[m%];
}
if(ans)printf("Alice\n");
else printf("Bob\n");
}
}
:
hdu 3032 Nim or not Nim?(搜索打SG表)的更多相关文章
- 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游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...
- 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 ...
- 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 ...
随机推荐
- PHP自定义函数使用外部变量
一般,php的自定义函数不能直接使用外部变量. 在php自定义函数中使用外部变量前,需要先使用global对外部变量进行声明. <?php $var = "hello World!& ...
- What is the difference between position: static,relative,absolute,fixed
What is the difference between static,relative, absolute,fixed we can refer to this link: expand
- 关于如何将Excel数据导入到SQL Server中
面对大量的Excel数据我们可能会非常苦恼,如果一条一条的插入到数据库:不仅会耗大量的时间,而且还可能会发生错误,现在我来说一下如何导入数据! 1.准备工作 首先要在Excel中建立数据表对应的数据字 ...
- [shell基础]——数组
数组赋值 1. 逐个数组元素赋值 # array[0]=11 # array[1]=22 # array[2]=33 # echo ${array[@]} 11 22 33 33 2. array( ...
- [2016-06-28]dhclient命令的进程没杀死,导致不断在向DHCP服务器获取IP
# Date:2016-06-28 # 问题:主机的配置文件/etc/sysconfig/network-scripts/ifcfg-eth0 已经配置好了静态的IP. 但隔几分钟主机的IP就自己变化 ...
- Git学习小结(第三次作业)
本文主要总结一下在学习和使用git中一些用到的命令. 参考教程:廖雪峰git教程 在windows上安装git 下载使用环境:http://msysgit.github.io/, 安装一路默认即可. ...
- C# 串口通信总结
在C#串口通信开发过程中有的产家只提供通信协议,这时候开发人员要自己根据协议来封装方法,有的产家比较人性化提供了封装好的通信协议方法供开发人员调用. 1.只提供通信协议(例如,今年早些时候开发的出钞机 ...
- 常用EXE文件反编译工具
PE Explorer V1.99 R5 绿色汉化特别版_强大的可视化汉化集成工具 功能极为强大的可视化汉化集成工具,可直接浏览.修改软件资源,包括菜单.对话框.字符串表等: 另外,还具备有 W32D ...
- C++中定义比较函数的三种方法
原文地址:http://fusharblog.com/3-ways-to-define-comparison-functions-in-cpp/ C++编程优与Pascal的原因之一是C++中存在ST ...
- 怪物AI(复习)
怪物AI执行 //-----------------------------------------------主动攻击---------------------------------------- ...