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 ...
随机推荐
- iPhone的震动 基于SDK8.0 Swift实现
导入AudioToolbox.framework包 在swift文件中 import AudioToolbox AudioServicesPlaySystemSound(SystemSoundID. ...
- 骇客(Hacker)用语
什么是TCP/IP 是一种网络通信协议,他规范了网络上所有的通信设备,尤其是一个主机与另一个主机之间的数据往来格式以及传送方式.,TCP/IP是INTERNET的基础 ...
- VC++编程中获取系统时间
<span style="white-space:pre"> </span>总结了在程序中如何获得系统时间的方法 void CGetSystenTimeDl ...
- mysql安装/启动报错汇总
2016/9/6补充 初始化报错: # /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysq ...
- Cocos2dx中利用双向链表实现无限循环滚动层
[Qboy原创] 在Cocos2dX 3.0 中已经实现一些牛逼的滚动层,但是对于有一些需要实现循环滚动的要求确没有实现,笔者在前段时间的一个做了一个游戏,需求是实现在少有的(13个)英雄中进行循环滚 ...
- web 性能忧化(IIS篇)
1. 调整IIS 7应用程序池队列长度 由原来的默认1000改为65535. IIS Manager > ApplicationPools > Advanced Settings 2. ...
- 静态数据认证(SDA)与动态数据认证(DDA)的区别
PBOC/EMV里有两个非常重要的概念,SDA(staticdataauthentication)和DDA(dynamicdataauthentication),分别叫做静态数据认证和动态数据认证.这 ...
- SqlServer正在执行的sql语句
SELECT [Spid] = session_Id ,ecid ,[Database] = DB_NAME(sp.dbid) ,[User] = nt_username ,[Status] = er ...
- M1分数分配
进过第一轮迭代我们依据工作量及质量决定分配分数方案: 王皓南 24.5分 黄宇冰 24分 申开亮 23.5分 许晋 21分 王宇杰 17分 吴润凡 16分 巴丹益昔 14分
- npm ERR!无法安装任何包的解决办法
npm ERR! Windows_NT 6.1.7601npm ERR! argv "E:\\node\\\\node.exe" "E:\\node\\node_modu ...