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

分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求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. Java-马士兵设计模式学习笔记-桥接模式

    一.概述 1.桥接模式的应用情况:(1)两个维度扩展(2)排列组合 二.代码 1.Gift.java public class Gift { protected GiftImpl giftImpl; ...

  2. Cornerstone问题

    // Cornerstone锁 Cornerstone locks a working copy whenever it performs operations suchs as commits, u ...

  3. MyBatis学习总结_02_使用MyBatis对表执行CRUD操作

    一.使用MyBatis对表执行CRUD操作——基于XML的实现 1.定义sql映射xml文件 userMapper.xml文件的内容如下: 1 <?xml version="1.0&q ...

  4. Ubuntu 12.04 SSH 安装

    By default Ubuntu Desktop OS comes with ssh clientpackage. It does not include ssh server package wh ...

  5. git - 简易指南

    http://www.bootcss.com/p/git-guide/ git - 简易指南

  6. Oracle Demo ->> CREATE TABLE

    Demo One CREATE TABLE employees_demo ( employee_id ) , first_name ) , last_name ) CONSTRAINT emp_las ...

  7. __init__ 和 self

    看代码 class A: def __init__(self, val): self.name = val def printName(self): print self.name a = A(&qu ...

  8. 在struts-config.xml中配置validator-plugin导致404 Servlet action is not available

    就是在struts-config.xml中添加了这么一段 <plug-in className="org.apache.struts.validator.ValidatorPlugIn ...

  9. 使用qmake生成Makefile

    Qmake自动生成Makefile 手动写Makefile是一件痛苦的事情,稍不小心就会出错,不过qmake可以让你脱离苦海 qmake可以根据你提供的.pro文件,生成Makefile不过他可比Ma ...

  10. 一个日期Js文件。 2013年10月12日 星期六 癸巳年九月初八

    1.简单用法 <div align="center">  <SCRIPT language=JavaScript src="js/calendar.js ...