HDU 3032 Nim or not Nim? (需求的游戏SG功能)
意甲冠军:经典Nim游戏转换,给你n礧pi,每个堆栈有pi石头,
Alice和Bob轮流石头,意一堆中拿走随意个石子,也能够将某一堆石子分成两个小堆
(每堆石子个数必须不能为0)。先拿完者获胜
思路:求SG函数后找规律。
SG函数定义及求法:点击打开链接
#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include <queue>
#include <stack>
#include<algorithm>
#include<set>
using namespace std;
#define INF 1e8
#define eps 1e-8
#define LL long long
#define maxn 1000001
#define PI acos(-1.0) int sg[maxn],vis[maxn]; void SG()
{
sg[0]=0;
sg[1]=1;
for(int i=2;i<100;i++)
{
memset(vis,0,sizeof(vis));
for(int j=i-1;j>=0;j--)
{
vis[sg[j]]=1;
}
for(int j=1;j<i;j++)
{
int state=sg[j]^sg[i-j];
vis[state]=1;
}
for(int j=0;j<maxn;j++)
{
if(!vis[j])
{
sg[i]=j;
break;
}
}
}
for(int i=97;i<maxn;i+=4)
{
sg[i]=i;
sg[i+1]=i+1;
sg[i+2]=i+3;
sg[i+3]=i+2;
}
}
int main()
{
SG();
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int st=0;
for(int i=0;i<n;i++)
{
int a;
scanf("%d",&a);
int p=a%4;
int m;
if(p==0)
{
m=a-1;
}
else if(p==3)
m=a+1;
else m=a;
st^=m;
}
if(st==0)
printf("Bob\n");
else printf("Alice\n");
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
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 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 ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
随机推荐
- bootstrap jQuery Ztree异步载入数据,check选择&可加入、改动、删除节点
效果图: 一.下载zTree插件 地址:http://www.ztree.me 二.html代码 <link href="../Scripts/zTree/css/zTreeStyle ...
- Unity3D发布WebPlayer时Failed to download data file解决方案
今天发布WebPlayer时, 发现直接打开html是可以正常运行的, 但是通过iis访问的话就会报错: Failed to download data file. 一开始以为是防火墙, 后来发现不是 ...
- windows phone 7 通过麦克风录音,并且播放
原文:windows phone 7 通过麦克风录音,并且播放 //模拟XNA的框架(凡是在wp7中应用xna的都必须先模拟此类) public class XNAAsyncDispatcher : ...
- Android 纯代码加入点击效果
项目中非常多的Button, 同一时候配置非常多button切图,Selector是不是非常烦, 使用以下这个类,就能够直接为Button添加点击效果. 不用多个图片,不用Selector. 使用方法 ...
- gc overhead limit exceeded eclipse错误解决方式
在Eclipse打包的时候报错:gc overhead limit exceeded eclipse 原因是Eclipse默认配置内存太小须要更改安装Eclipse目录下的eclipse.ini文件. ...
- mybatis与mysql插入时返回主键id的值
<insert id="insertCharge" parameterType="com.bb.bean.Rechargerecord"> < ...
- React Native环境配置
React Native环境配置 史上最全Windows版本搭建安装React Native环境配置 配置过React Native 环境的都知道,在Windows React Native环境配置有 ...
- 如何使用ZEROBRANE STUDIO远程调试COCOS2D-X的LUA脚本(转)
http://www.cocos2d-x.org/docs/manual/framework/native/v2/lua/lua-remote-debug-via-zerobrane/zh ZeroB ...
- 使用vbs脚本添加域网络共享驱动器
MapNetworkDrive Method Adds a shared network drive to your computer system. object.MapNetworkDrive(s ...
- 重新想象 Windows 8 Store Apps (31) - 加密解密: 哈希算法, 对称算法
原文:重新想象 Windows 8 Store Apps (31) - 加密解密: 哈希算法, 对称算法 [源码下载] 重新想象 Windows 8 Store Apps (31) - 加密解密: 哈 ...