hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的。
分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求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函数)的更多相关文章
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)
Fibonacci again and again Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & ...
- hdu 5795 A Simple Nim 博弈sg函数
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- HDU-4678 Mine 博弈SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...
- 尼姆博弈+SG函数
博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...
- hdu_1848_Fibonacci again and again(博弈sg函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:给你3堆石子,每次只能取fibonacci数的石子,问先手是否能赢 题解:SG函数模版题 ...
- hdu 1848 简单SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...
- (转)博弈 SG函数
此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------- ...
- 【转】博弈—SG函数
转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...
随机推荐
- hdu 2964 Prime Bases(简单数学题)
按照题意的要求逐渐求解: #include<stdio.h> #include<string.h> #include<algorithm> using namesp ...
- Android核心分析之十八Android电话系统之RIL-Java
Android RIL-Java 123.jpg (2.09 KB, 下载次数: 1) 下载附件 保存到相册 2012-3-21 10:47 上传 RIL-Java在本质上就是一个RIL代理,起 ...
- hive-学习笔记
1.hive模糊搜索表 show tables like '*name*'; 2.查看表结构信息 desc formatted table_name; desc table_name; 3.查看 ...
- iOS开发--应用程序上线
iOS应用上线 http://www.jianshu.com/p/ffddc5e5f0b9 iOS真机测试 http://www.jianshu.com/p/986e02d38f1b iOS应用程序打 ...
- 笔者带你剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER)
注:本文部分内容引用本人博客http://gao-xianglong.iteye.com/blog/1973591 前言 在开始讲解淘宝的TDDL(Taobao Distribute Data L ...
- AdventureWorksDW2008R2 attach: Unable to open the physical file. Operating system error 5: "5(Access is denied.)
http://stackoverflow.com/questions/26014133/adventureworksdw2008r2-attach-unable-to-open-the-physica ...
- SSIS -->> Data Type
SSIS和SQL SERVER, .NET数据类型的映射表
- linux 僵死进程
僵死进程简而言之就是:子进程退出时,父进程并未对其发出的SIGCHILD信号进行适当处理,导致子进程停留在僵死状态等待其父进程为其收尸,这个状态下的子进程就是僵死进程. 在fork()/execve( ...
- java eclise的配置
java eclise的配置 http://jingyan.baidu.com/album/870c6fc33e62bcb03fe4be90.html?picindex=24
- Java用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间
package com.zrar.date; import java.util.Calendar; /** * * 描述:此类用于取得当前日期相对应的月初,月末,季初,季末,年初,年末,返回值均为St ...