hdu2999 Stone Game, Why are you always there?---sg 一排石子分成若干堆
来源:互联网 发布:qq三国js装备四象搭配 编辑:程序博客网 时间:2024/05/21 09:51
Stone Game, Why are you always there?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 142 Accepted Submission(s): 53
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...”
......
“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.
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
31 5 111
Sample Output
1
Source
2009 Multi-University Training Contest 19 - Host by BNU
Recommend
chenrui
时间很紧~~~
#include<iostream>#include<cstdlib>#include<stdio.h>#include<memory.h>#include<algorithm>using namespace std;int fibo[110];int sg[1010];int num[1010],n;int solve(int x){ if(sg[x]>=0) return sg[x]; memset(num,-1,sizeof(num)); for(int i=0;i<n;i++) for(int j=x-fibo[i];j>=0;j--) { num[solve(j)^solve(x-fibo[i]-j)]=1; } for(int i=0;;i++) if(num[i]==-1) return sg[x]=i;}int main(){ int m,k; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++)scanf("%d",&fibo[i]); sort(fibo,fibo+n); scanf("%d",&m); memset(sg,-1,sizeof(sg)); sg[0]=0; while(m--) { scanf("%d",&k); if(solve(k)) puts("1"); else puts("2"); } } return 0;}
- hdu2999 Stone Game, Why are you always there?---sg 一排石子分成若干堆
- hdu2999 Stone Game, Why are you always there?
- hdu2999 Stone Game, Why are you always there? 组合NIM
- HDU 2999 Stone Game, Why are you always there? (构造 SG函数)
- HDOJ 2999 Stone Game, Why are you always there? 博弈 SG函数
- HDOJ 2999 Stone Game, Why are you always there? 博弈 SG函数
- Stone Game, Why are you always there? - HDU 2999 sg函数
- HDU 2999 Stone Game, Why are you always there?
- hdu 2999 Stone Game, Why are you always there?
- hdu2999Stone Game, Why are you always there?
- zoj2083 Win the Game-----博弈 一排石子分成若干堆
- hdu3980 Paint Chain------sg 环--链 一排石子分成若干堆
- Why are you always smiling?
- hdu1729 Stone Game sg
- Somebody~why I can not be there where you are??????????????
- hdu Stone Game SG函数
- HDU1729 Stone Game (SG函数)
- HUD 1729 Stone Game(SG)
- mysql--复杂sql语句解析
- ffmpeg命令
- Spring---->环境 及 为什么使用spring
- 淡淡的微笑,静悄悄地过
- vim 光标回退
- hdu2999 Stone Game, Why are you always there?---sg 一排石子分成若干堆
- Eclipse及常用插件安装下载地址
- 关于ios应用有时候黑屏得问题
- 分享45个android实例源码,很好很强大.收藏吧!!!
- 海量数据处理问题
- 框架CI与YII之个人见解1
- SQL中IN,NOT IN,EXISTS,NOT EXISTS的用法和差别
- iptables 防火墙使用
- MyEclipse6.0编译后的类无法自动发不到WebRoot/WEB-INF/classes文件夹下(转)