hdu 2999 sg函数(简单博弈)
Stone Game, Why are you always there?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 393 Accepted Submission(s):
132
“Err....
Feel bored about the stone game? Don’t be so, because stone game changes all the
time!”
“What the hell are they thinking for?”
“You know, whenever Alice is
trying to make fun of Bob, she asked him to play stone game with him.”
“Poor
Bob... What’s the rule today?”
“It seems Alice only allows some fixed numbers
of continuous stones can be taken each time. And they begin with one string of
stones.”
“A string? Formed as a circle or a line?”
“A line.”
“Well, I
think I may help Bob with that.”
“How?”
“I may tell him to skip this round
if he has no chance to win.”
“Good idea maybe, I mean, Alice always let Bob
play first, because she think herself is smart enough to beat Bob no matter
how.”
“Yes, she’s actually right about herself. Let me see if Bob has a
chance to win...”
......
case:
The first line has a positive integer N (1<=N<=100).
The
second line contains N positive integers, a1, a2 ... an, separated by spaces,
which indicate the fixed numbers Alice gives.
The third line, a positive
integer M. (M<=1000)
Following M lines, one positive integer K
(K<=1000) each line. K means in this round, the length of the stone string.
output “2” if Bob has no chance, or “0” if it’s undeterminable.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn=;
int sg[maxn],Set[],num; int mex(int n)
{
if(sg[n]!=-) return sg[n];
bool flag[maxn];
int i,j;
memset(flag,false,sizeof(flag));
for(i=;i<num && n>=Set[i];i++)
{
for(j=;j<=n-Set[i]+;j++)
{
sg[j-]=mex(j-);
sg[n-j-Set[i]+]=mex(n-j-Set[i]+);
flag[sg[j-]^sg[n-j-Set[i]+]]=true;
}
}
for(i=;i<maxn;i++)
if(!flag[i])
return sg[n]=i;
} int main()
{
int n,m,k,i;
while(~scanf("%d",&n))
{
memset(sg,-,sizeof(sg));
sg[]=;
for(i=;i<n;i++) scanf("%d",Set+i);
sort(Set,Set+n);num=;
for(i=;i<n;i++) if(Set[i]!=Set[num-]) Set[num++]=Set[i];//去重
scanf("%d",&m);
while(m--)
{
scanf("%d",&k);
if(sg[k]==-) sg[k]=mex(k);
if(sg[k]) puts("");
else puts("");
}
}
return ;
}
hdu 2999 sg函数(简单博弈)的更多相关文章
- bzoj 1188 [HNOI2007]分裂游戏(SG函数,博弈)
1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 733 Solved: 451[Submit][Status ...
- hdu 1847(SG函数,巴什博弈)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 1848 Fibonacci again and again SG函数做博弈
传送门 题意: 有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数. 思路: 利用SG函数求解即可. /* * @Author: chenkexing * @D ...
- hdu 2147 SG函数打表(手写也可以) 找规律
kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others) Total ...
- HDU-1848-Fibonacci again and again(SG函数,博弈)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意: 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样 ...
- HDU 1536 sg函数
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 1536 SG函数模板题
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- hdu 1848(SG函数)
Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- gym/102059/problem/I. Game on Plane SG函数做博弈
传送门: 题意: 给定一个正n边形的点.双方轮流连点成线,要求所画的线不能与之前的线相交.当某个人连成一个回路,这个人就输了.问先手必胜还是后手必胜. 思路: SG函数,因为一条线相当于把图劈成了两半 ...
随机推荐
- VMware vSphere6.0 服务器虚拟化部署安装图解
一 VMware vSphere部署的前期规划要点 1 vSphere的优点 (略) 2 如何利用现在的设备架构虚拟化环境 在虚拟化过程中,用户大多会考虑目前现有的服务器.存储.交换机等基础设备是否可 ...
- Mybatis学习记录(1)
1.Mybatis介绍 Mybatis是apache的一个开源项目iBatis,Mybatis是一个优秀的持久层框架,他对jdbc的操作数据库的过程进行封装,使开发者只需要关注sql本身,不需 ...
- dSYM文件
来到新公司后,前段时间就一直在忙,前不久 项目 终于成功发布上线了,最近就在给项目做优化,并排除一些线上软件的 bug,因为项目中使用了友盟统计,所以在友盟给出的错误信息统计中能比较方便的找出客户端异 ...
- 响应者链和Hit-Test 机制
概念: 响应者 : 对用户交互动作事件进行响应的对象.响应者链:成为处理事件的响应者的先后顺序链. 1.Hit-Test 机制 当用户触摸(Touch)屏幕进行交互时,系统首先要找到响应者(Respo ...
- Postgres-XL的限制
Postgres-XL是基于PostgreSQL的一个分布式数据库. 相比于PostgreSQL,XL的表的数据是可以分布到不同的datanode上的,对存在于不同的datanode上的数据进行处理, ...
- 洛谷 1571 眼红的Medusa
洛谷 1571 眼红的Medusa 虽说这道题标签里写明了二分,然而我还是首先想到了map......毕竟map真的是简单好写. map做法 #include<bits/stdc++.h> ...
- FastJsonUtils工具类
fastjson是由alibaba开源的一套json处理器.与其他json处理器(如Gson,Jackson等)和其他的Java对象序列化反序列化方式相比,有比较明显的性能优势. 版权声明:本文为博主 ...
- 使用sprunge粘贴文字
在irc里面请教的时候,需要输出很多文本,irc禁止输入多行文字. 使用sprunge可以返回一个网址,省去复制粘贴的麻烦. 1> 简单使用: command | curl -F "s ...
- goalng导出excel(csv格式)
最近项目中有个小需求,需要将查询结果导出到excel.之间前java比较容易,使用POI很容易就能实现,查了下golang的文档,发现golang下边并没有导出excel的包,但是却有一个encodi ...
- 强大的with语句
上下文管理器对象存在的目的是管理 with 语句,就像迭代器的存在是为了管理 for 语句一样. with 语句的目的是简化 try/finally 模式.这种模式用于保证一段代码运行完毕后执行某项操 ...