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函数,因为一条线相当于把图劈成了两半 ...
随机推荐
- JavaScript -- DOM事件
什么是事件 事件就是文档或浏览器窗口中发生的一些特定的交互瞬间.比如你在网页上见到的鼠标点击一个按钮,按钮的颜色发生了变化,就是因为这个标签绑定了点击事件 鼠标事件 onload:页面加载时触发 on ...
- echarts实现仪表盘(自己动起来,没有后端,顺便重温math.random
let a = parseInt(Math.random() * (2 + 1), 10); let arr = []; arr.push(res[a]); let option = { toolti ...
- Java中的集合Collection接口
/* 集合:集合是存储对象数据的集合容器.集合比数组的优势: 1. 集合可以存储任意类型的对象数据,数组只能存储同一种数据类型 的数据. 2. 集合的长度是会发生变化的,数组的长度是固定的.----- ...
- iOS应用架构谈part4-本地持久化方案及动态部署
前言 嗯,你们要的大招.跟着这篇文章一起也发布了CTPersistance和CTJSBridge这两个库,希望大家在实际使用的时候如果遇到问题,就给我提issue或者PR或者评论区.每一个issue和 ...
- 如何使用postman做接口测试
1.get请求传参 只要是get请求都可以在浏览器中直接发: 在访问地址后面拼 ?key=value&key=value 例如: 在浏览器中直接输入访问地址,后面直接拼需要传给服务器的参数 ...
- SEO 优化
1.什么是SEO优化: 简单的来说就是了解搜索引擎的排名规则,投机所好,让我们的网站在搜索引擎上得到靠前的排名,获取更多流量的一种方式. 2.SEO优化-衡量标准 关键词的排名--核心关键词的效果 收 ...
- matplotlib学习记录 二
# 绘制10点到12点的每一分钟气温变化折线图 import random from matplotlib import pyplot as plt # 让matplotlib能够显示中文 plt.r ...
- 网络编程基础socket 重要中:TCP/UDP/七层协议
计算机网络的发展及基础网络概念 问题:网络到底是什么?计算机之间是如何通信的? 早期 : 联机 以太网 : 局域网与交换机 广播 主机之间“一对所有”的通讯模式,网络对其中每一台主机发出的信号都进行无 ...
- ogre3D学习基础8 --- 资源管理器
资源管理 可管理的资源有: 材质资源:在.material文件中包含的材质脚本定义(技术.通路.纹理单元等数据的定义). 模型资源:经过优化的二进制网格模型文件,扩展名为.mesh.包含几何信息和一些 ...
- 关于面试总结-SQL学生表
前言 每次面试必考SQL,小编这几年一直吃SQ的亏,考题无非就是万年不变学生表,看起来虽然简单,真正写出来,还是有一定难度.于是决定重新整理下关于SQL的面试题,也可以帮助更多的人过SQL这一关. 作 ...