意甲冠军:经典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功能)的更多相关文章

  1. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  8. HDU 3094 树上删边 NIM变形

    基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...

  9. HDU 3032 multi-sg 打表找规律

    普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...

随机推荐

  1. 共同发展一个以上的开发者账户多台电脑 证书 p12 型材 进出口

    1:导出相应的开发人员证书的配置文件. 2:依据相应的app id 创建配置文件. 3:打开钥匙串,把你的公布证书导出p12文件. 4:用开发人员账号导出developerprofile文件. 5:把 ...

  2. 天翼玩家wifi,鸡肋or神器?

    昨天,天一在成都,一个举行4G体验活动.谁是背着一个婴儿每一翼4G MiFi终奌站.市民可进入用户password自由的直接经验wifi互联网. 天翼随身wifi是什么? 这样的4G MiFi就是天翼 ...

  3. pygame系列_箭刺Elephant游戏

    这个游戏原名为:Chimp,我们可以到: http://www.pygame.org/docs/tut/chimp/ChimpLineByLine.html 获取到源码和详细的源码讲解 下面是我对游戏 ...

  4. tarjan+缩点

    B - Popular Cows Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Su ...

  5. in与exist , not in与not exist 的区别(转)

    in和exists  in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询.一直以来认为exists比in效率高的说法是不准确的.  如果查询的 ...

  6. 第五章_JSTL

    5.1.下载JSTL http://jstl.java.net 5.2.JSTL类库 类别 下属功能 URI 前缀 Core 变量支持 http://java.sun.com/jsp/jstl/cor ...

  7. C#操作注册表--DarrenF

    步骤/方法 读取指定名称的注册表的值 private string GetRegistData(string name) { string registData; RegistryKey hkml = ...

  8. The example program of C on point

    计划一: #include<stdio.h> #define N_VALUES 5 int main( void ) { float values[N_VALUES]; float *vp ...

  9. URAL 1934 Black Spot --- 最短的简单修改

    右侧是1.维护的同时保持最短路p值至少,我有直接存款(1-p).该概率不满足,为了使这个值极大. #include <iostream> #include <cstdlib> ...

  10. Ubuntu下安装KDE及安装中文环境

    进入Ubuntu的默认安装的桌面后打开终端,输入 sudo apt-get install kubuntu-desktop 回车后输入密码接下来提示下载KDE需要多少空间,解压后需要多少空间,询问是否 ...