题意:

  有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表)的更多相关文章

  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游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...

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

  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?(博弈,SG打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

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

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

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

  9. HDU 3094 树上删边 NIM变形

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

随机推荐

  1. 014--VS2013 C++ c++定时动画

    资源图片 //全局变量HBITMAP girl[7];HDC mdc, hdc;int num; //--------------------------------------------InitI ...

  2. 3. 戏说VHDL之入门游戏一:流水灯

    一.   流水灯 1.1流水灯原理 流水灯是每个学电子的入门“游戏” ,示意图如图1,其原理极其简单,但是可玩性却极强,可以就8个LED写出不同花样的程序.在1.2中我们列出两个不同思路的代码作为VH ...

  3. ios 唯一标示符

    大家知道苹果每部 iOS 设备都有一个 UDID,它就像设备的身份证一样,记录着设备的名称.类型甚至一些关于用户的私人信息.通常情况下,UDID 的一个最大功能就是帮助广告发布商向特定用户推送定向广告 ...

  4. Android 上传图片到 Asp.Net 服务器的问题

    最近在做一个手机app联合系统管理做的应用程序,管理程序管理数据的发布和增删改查,手机app负责显示和操作业务逻辑这么一个功能. 刚开始路走的都很顺,但是走到通过Android客户端上传图片到Asp. ...

  5. JavaScript DOM动态创建(声明)Object元素

    http://www.cnblogs.com/GuominQiu/archive/2011/04/01/2002783.html 一文提及“等整个页面加载完毕后,根据用户所选的阅读机类型,再用Java ...

  6. SQL SERVER数据库修改是否区分大小写

    昨天去客户,发现程序无法应用,跟踪错误提示,提示的大致意思是“数据库表名和数据库字段名不存在”.查询后发现是SQL Server数据库设置了区分大小写的缘故(一般安装时,Oracle的正确安装下是默认 ...

  7. ffmpeg 发布hls流

    本来主要讲述如何利用ffmpeg将输入视频流通过转码的方式转成m3u8文件.如何通过http的方法将切边推送给客户端,不在本文中讲述. 输入视频流可以是rtsp流,也可以是http,还可以是文件等等. ...

  8. 解决a different object with the same identifier value was already associated with the session错误

    [转]解决a different object with the same identifier value was already associated with the session错误 这个错 ...

  9. Restful API 最佳实践 (理论篇)

    参考: http://www.ibm.com/developerworks/cn/web/1103_chenyan_restapi/ 规划好 资源标示结构 和 URI模式, 是API设计成功的关键 原 ...

  10. 二分--LIGHTOJ 1088查找区间(水题)

    #include <iostream> #include <cstdio> #include <cmath> using namespace std; const ...