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函数,因为一条线相当于把图劈成了两半 ...
随机推荐
- CPP-基础:新标准 C++iostream
在新的标准 C++ iostream 库中: 1. open 函数不采用第三个参数(保护参数). 2. 无法从文件句柄创建流. 3. 除了几个例外,新的标准 C++ 库中的所有名称都在 std 命名空 ...
- javaweb基础(20)_JavaBean总结
一.什么是JavaBean JavaBean是一个遵循特定写法的Java类,它通常具有如下特点: 这个Java类必须具有一个无参的构造函数 属性必须私有化. 私有化的属性必须通过public类型的方法 ...
- React支持装饰器
在用mobx时用到了装饰器,无奈环境不支持装饰器,搜索了半天,网上教程乱七八糟,最后想到了babel官网上肯定有,一搜果然有,安装教程 见Babel官网. 最快捷的教程是官网文档
- 【NOIP提高A组模拟2018.8.14】 区间
区间加:差分数组修改 O(n)扫描,负数位置单调不减 #include<iostream> #include<cstring> #include<cstdio> # ...
- CentOS7安装配置VSFTP
#是否开启匿名用户,匿名都不安全,不要开 anonymous_enable=NO #允许本机账号登录FTP local_enable=YES #允许账号都有写操作 write_enable=YES # ...
- Python爬虫系列-PyQuery详解
强大又灵活的网页解析库.如果你觉得正则写起来太麻烦,如果你觉得BeautifulSoup语法太难记,如果你熟悉jQuery的语法,那么PyQuery就是你的最佳选择. 安装 pip3 install ...
- java代码导出数据到Excel、js导出数据到Excel(三)
jsp内容忽略,仅写个出发按钮: <button style="width: 100px" onclick="expertExcel()&quo ...
- Python模块(三)(正则,re,模块与包)
1. 正则表达式 匹配字符串 元字符 . 除了换行 \w 数字, 字母, 下划线 \d 数字 \s 空白符 \n 换行符 \t 制表符 \b 单词的边界 \W \D \S 非xxx [ ...
- eclipse使用技巧的网站收集——转载(二)
写代码离不开文本编辑器,看代码也离不开,iar和keil编辑和阅读简直一般般了,因此使用eclipse可以看看代码,提高效率.网上有几个博客的文章,这里收集一下,以备忘. 以下文章转载自:http:/ ...
- jmeter中基于oracle的JDBC Request的使用
前提条件: 1.有数据库:2.数据库中有表,例如testuser(userid,username,usepwd): 设置如下: 参考自:http://www.linuxidc.com/Linux/20 ...