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

Problem Description
“Alice and Bob are playing stone game...”
“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...”
......
 
Input
There are multiple test cases, for each test
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
For each K, output “1” if Bob has a chance to win,
output “2” if Bob has no chance, or “0” if it’s undeterminable.
 
Sample Input
3
1 5 1
1
1
 
Sample Output
1
 
题目大意:给一个正整数集合,给一串连续在石头,每次只能取集合中元素个连续的石头,每次都是最优操作,判断是先手必胜还是后手必胜。
 
 
 #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函数(简单博弈)的更多相关文章

  1. bzoj 1188 [HNOI2007]分裂游戏(SG函数,博弈)

    1188: [HNOI2007]分裂游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 733  Solved: 451[Submit][Status ...

  2. hdu 1847(SG函数,巴什博弈)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  3. HDU 1848 Fibonacci again and again SG函数做博弈

    传送门 题意: 有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数. 思路: 利用SG函数求解即可. /* * @Author: chenkexing * @D ...

  4. hdu 2147 SG函数打表(手写也可以) 找规律

    kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others) Total ...

  5. HDU-1848-Fibonacci again and again(SG函数,博弈)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意: 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样 ...

  6. HDU 1536 sg函数

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  7. hdu 1536 SG函数模板题

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. hdu 1848(SG函数)

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  9. gym/102059/problem/I. Game on Plane SG函数做博弈

    传送门: 题意: 给定一个正n边形的点.双方轮流连点成线,要求所画的线不能与之前的线相交.当某个人连成一个回路,这个人就输了.问先手必胜还是后手必胜. 思路: SG函数,因为一条线相当于把图劈成了两半 ...

随机推荐

  1. Makefile 编写实例

    make命令常用的三个选项: 1.-k:它的作用是让make命令在发现错误的时候仍然继续执行.我们可以利用这个选项在一次操作中发现未编译成功的源文件. 2.-n:它的作用是让make命令输出将要执行的 ...

  2. javaweb基础(15)_jsp基础语法

    任何语言都有自己的语法,JAVA中有,JSP虽然是在JAVA上的一种应用,但是依然有其自己扩充的语法,而且在JSP中,所有的JAVA语句都可以使用. 一.JSP模版元素 JSP页面中的HTML内容称之 ...

  3. HTML5<nav>元素

    HTML5中<nav>元素定义页面导航链接的部分区域,但并不是所有的链接都放到nav元素里面. 实例: <header id="pageHeader"> & ...

  4. PAT 乙级 1086

    题目 题目地址:PAT 乙级 1086 思路 本题比较简单,但还是存在小小的坑点,简单说一下: 倒置中需要注意的唯一问题就是:100倒置后不是001,而是1:这个问题处理之后还要注意另一个点就是,10 ...

  5. 【android】签署应用采用相同证书的用处

    在应用的预期生命周期内,您应使用相同证书签署所有 APK 应用升级:当系统安装应用的更新时,它会比较新版本和现有版本中的证书.如果证书匹配,则系统允许更新.如果您使用不同的证书签署新版本,则必须为应用 ...

  6. German Collegiate Programming Contest 2018​

    // Coolest Ski Route #include <iostream> #include <cstdio> #include <cstring> #inc ...

  7. BZOJ 2687: 交与并

    答案存在于 1.两个互相包含的区间 2.两个互不包含的区间 决策单调性显然 但是这代码很精妙啊,并不知道这个为什么能这样写 #include<cstdio> #include<alg ...

  8. BZOJ 5313: 新Fib数列

    打表找规律 #include<cstdio> using namespace std; int F[20]={0,1,1,2,3,0,3,3,1,4,0,4,4,3,2,0,2,2,4,1 ...

  9. html5/css3常考面试题

    一.HTML5 CSS3 CSS3有哪些新特性? 1. CSS3实现圆角(border-radius),阴影(box-shadow), 2. 对文字加特效(text-shadow.),线性渐变(gra ...

  10. struts2对properties资源的处理

    struts2对properties资源的处理 做了一些功能增强 包括: 可以读取项的描述 可以读取项所在的行号,文件路径等 实现方式 继承了java的java.util.Properties实现了一 ...