题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的。

分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办法求得sg的规律。

通过打表找规律可以得到如下规律:if(x%4==0) sg[x]=x-1; if(x%4==1||x%4==2) sg[x]=x; if(x%4==3) sg[x] = x+1。

打表代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; int sg[]; int calsg(int x)
{
int next[],i,flag;
memset(next,,sizeof(next)); for(i=;i<=x/;i++)
{
flag=sg[i]^sg[x-i];
// printf("%d %d\n",sg[i],sg[x-i]);
next[flag]=;
} for(i=;i<=x;i++)
{
if(sg[x-i]==-)
sg[x-i]=calsg(x-i);
next[sg[x-i]]=;
} for(i=; ;i++)
if(next[i]==)
return i;
} int main()
{
int i;
memset(sg,-,sizeof(sg));
sg[]=;sg[]=;
//sg[2]=2;
printf("0\n1\n");
for(i=;i<=;i++)
{
sg[i]=calsg(i);
printf("%d\n",sg[i]);
} return ;
}

ac代码:

#include<stdio.h>
#include<string.h>
#include<math.h> int n; int main()
{
int T,i,res,x;
scanf("%d",&T);
while(T--)
{
res=;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",&x);
if(x%==)
res=res^(x-);
else if(x%==||x%==)
res=res^(x);
else
res=res^(x+);
}
if(res!=)
printf("Alice\n");
else
printf("Bob\n");
}
return ;
}

hdu 3032(博弈sg函数)的更多相关文章

  1. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  2. HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)

    Fibonacci again and again Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & ...

  3. hdu 5795 A Simple Nim 博弈sg函数

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Pro ...

  4. HDU-4678 Mine 博弈SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...

  5. 尼姆博弈+SG函数

    博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...

  6. hdu_1848_Fibonacci again and again(博弈sg函数)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:给你3堆石子,每次只能取fibonacci数的石子,问先手是否能赢 题解:SG函数模版题 ...

  7. hdu 1848 简单SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...

  8. (转)博弈 SG函数

    此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------- ...

  9. 【转】博弈—SG函数

    转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...

随机推荐

  1. ps -ef能列出进程号,和端口号没任何关系

    1.ps -ef显示所有进程ID 2.netstat才显示端口号情况

  2. 【web性能】js应该放在html页面的什么位置

    所有浏览器在下载JS的时候,会阻止一切其他活动,比如其他资源的下载,内容的呈现等等.至到JS下载.解析.执行完毕后才开始继续并行下载其他资源并呈现内容.   外部JS的阻塞下载 所有浏览器在下载JS的 ...

  3. Combiner

    如果job 设置了 combiner ,则job的每个map运行的数据会先进入combiner,然后再通过patitioner分发到reduce.通过combiner能减少reduce的计算.空间压力 ...

  4. 了解python

    Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.Python的文本文件是.py文件 Python的用途: 1.做日常事务,比如自动备份你的MP3 2.可以做网站,很多著名的网站包括 ...

  5. android ADB命令的使用

    http://jingyan.baidu.com/article/fcb5aff7f55c63edab4a7174.html 综上所述,我觉得告知各位菜鸟同学如何删除自带的程序是很有必要的一件事情.1 ...

  6. code manager tools git的使用;

    git的使用 一.下载及安装: 1.下载:https://github.com 2.安装: 二.常用命令: 查看.添加.提交.删除.找回,重置修改文件 git help< command> ...

  7. Vim 新用法

    daw , delete a word cw , delete from cursor to the end then insert mode a word 移动: f ; Aa Oo Cc Ii S ...

  8. CVS数据的导入和导出

    2.CSV导入/导出测试 package junit.test; import java.io.File; import java.util.ArrayList; import java.util.L ...

  9. [转]深入hibernate的三种状态

    学过hibernate的人都可能都知道hibernate有三种状态,transient(瞬时状态),persistent(持久化状态)以及detached(离线状态),大家伙也许也知道这三者之间的区别 ...

  10. 函数lock_rec_add_to_queue

    在原来的type_mode基础上,加上LOCK_REC /*********************************************************************// ...