hdu2999 Stone Game, Why are you always there?
来源:互联网 发布:单片机温度控制系统 编辑:程序博客网 时间:2024/05/18 00:29
Stone Game, Why are you always there?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 353 Accepted Submission(s): 117
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直接求出sg函数值来就可以了!#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;#define mem(a,b) memset(a,b,sizeof(a))#define M 10050int pri[M],a[M],cnt;int getsg(int n){ if(pri[n]!=-1)return pri[n]; int vis[M]; mem(vis,0); for(int i=0;i<cnt&&a[i]<=n;i++){ for(int j=0;j<=n-a[i];j++){ if(pri[j]==-1)pri[j]=getsg(j); if(pri[n-j-a[i]]==-1)pri[n-j-a[i]]=getsg(n-j-a[i]); vis[pri[j]^pri[n-j-a[i]]]=1; } } for(int i=0;;i++) if(!vis[i]) return i;}int main(){ int n,i,k,x; while(scanf("%d",&n)!=EOF){ mem(pri,-1); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); for(i=1,cnt=0;i<n;i++){ if(a[i]!=a[cnt])a[++cnt]=a[i]; } cnt++; scanf("%d",&k); for(i=0;i<k;i++){ scanf("%d",&x); if(getsg(x))printf("1\n"); else printf("2\n"); } } return 0;}
- hdu2999 Stone Game, Why are you always there?
- hdu2999 Stone Game, Why are you always there? 组合NIM
- hdu2999 Stone Game, Why are you always there?---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?
- 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函数
- Why are you always smiling?
- Somebody~why I can not be there where you are??????????????
- Why are you crying?
- Why are you smiling?
- Why you should always use PHP interfaces
- leehom,you are always be my star
- You will never understand love if you are always sane
- Always There
- [Accessibility] Missing contentDescription attribute on image
- request 获取各项参数以及意义
- Android开发优化之——对Bitmap的内存优化
- Android开发优化之——使用软引用和弱引用
- java术语{PO/POJO/VO/BO/DAO/DTO}
- hdu2999 Stone Game, Why are you always there?
- 开发中遇到的各种坑爹错误及修改
- 一颗不羁的心
- tomcat中jsp引用图片img的src属性带中文路径无法显示的解决
- HDU 1754 I Hate It (线段树初步point的修改)HDU 3074 Multiply game (增加同余定理)
- Java多线程值之定时器Timer
- java 方法重载的判定
- dscuzX2.5 数据字典
- 基于JVM的服务端javascript平台Ringo.js入门(一)