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 ...
随机推荐
- Jndi使用好处,与简单实例【JBOSS】
JNDI是 Java 命名与目录接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之一,不少专家认为,没有透彻理解JNDI的意义和作用,就没有 ...
- C/S与B/S谁与争锋之我见
看到网上有些人在讨论C/S架构和B/S架构以及它们的发展趋势,后起之秀B/S是否真将取代C/S而存在?在发表我的观点之前,我们先来一起来回顾下C/S以及B/S. 一C/S 1.C/S概念 C/S是Cl ...
- java基金会成立Set
1.设置 当向集合Set中添加对象时.首先集合计算要添加对象的hashcode,依据该值得到一个位置用来存放当前的对象,当在该位置没有一个对象存在的时候,集合set觉得该对象在集合中不存在,直接添加进 ...
- matlab secant method
% Matlab script to illustrate the secant method % to solve a nonlinear equation % this particular sc ...
- iOS游戏开发游戏功能之外的东西
对于一个游戏的开发,我们除了完毕游戏的功能之外,还有多少东西我们须要考虑呢? 非常多.也非常烦! 但做过一遍之后下一次就会非常easy. 都有什么东西我们想加入到游戏其中呢? (1)分享功能 (2)评 ...
- Windows Phone开发(1):概论
原文:Windows Phone开发(1):概论 Windows Phone是微软公司开发的手机操作系统,这里就不多介绍,和Android,iPhone一样运行在智能手机上,相信大家都很熟悉. 目前来 ...
- 在SQLAlter在现场一定的价值
update AA set aa = replace(aa,'1234','规范') where aa like '%1234%'
- Ext JS4百强应用: 做可编辑的,可checked的treegrid--第11强
做一个可编辑的,可checked的treegrid,代码相当简洁: 请看代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN&quo ...
- (摘录)SQL Server 存储过程
文章摘录:http://www.cnblogs.com/hoojo/archive/2011/07/19/2110862.html SQL Server 存储过程 Transact-SQL中的存储过程 ...
- [2014 Regional]牡丹江 H Hierarchical Notation 做题记录
主妇:老年人谁是炮灰牡丹江,我们的团队只是做同步大赛 他决定开爆震H什么时候,A 5min 1Y.I在该限制后,纠结了很久30min+ 1Y,神继续承担各种位置卡D在,hpp见B我认为这是非常熟悉的研 ...