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 ...
随机推荐
- iOS js oc相互调用(JavaScriptCore)(二)
下来我们使用js调用iOS js调用iOS分两种情况 一,js里面直接调用方法 二,js里面通过对象调用方法 首先我们看第一种,直接调用方法. 其中用到了iOS的block 上代码 -(void)we ...
- Echarts事件
Echart饼图.柱状图.折线图(pie.bar.line)添加点击事件发布日期:2014年08月10日 来源:PHP1.CN 点击:250638摘要:var myChart= echar ...
- struts2不兼容servlet、COS
如果你在一个项目中使用了struts2,也就是说,你在web.xml中配置了如下代码: <filter> <filter-name>struts2</filter-nam ...
- php pod
//PDO:数据访问抽象层 //dsn:数据源: //带有事务功能: $dsn = "mysql:host=localhost;dbname=mydb"; ——建立数据源 //造p ...
- js调用高德API获取所在当前城市
可以在js代码中直接调用API接口,获取所处当前城市信息,代码如下: <script type="text/javascript"> function getCurre ...
- MAVEN “Plugin execution not covered by lifecycle configuration”
pom文件中报错提示: Plugin execution not covered by lifecycle configuration: net.alchim31.maven:yuicompresso ...
- HDU 4638 Group(分组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 题意:给出一个数列,若干询问.每次询问区间[L,R]的最少有多少段?每一段是连续的一段且这段内的 ...
- Server-Side UI Automation Provider - WPF Sample
Server-Side UI Automation Provider - WPF Sample 2014-09-14 引用程序集 自动化对等类 WPF Sample 参考 引用程序集 返回 UIAut ...
- Android--动态添加控件
[html] [html] package com.mrzhu.edittest; import android.app.Activity; import ...
- 如何在linux console中显示当前你在的branch?
http://stackoverflow.com/questions/17333531/how-can-i-display-the-current-branch-and-folder-path-in- ...