UVa 10404 Bachet's Game(DP)

来源:互联网 发布:数据库发展历史 编辑:程序博客网 时间:2024/05/22 04:25

Bachet's Game

Bachet's game is probably known to all but probably not by this name. Initially there are nstones on the table. There are two players Stan and Ollie, who move alternately. Stan always starts. The legal moves consist in removing at least one but not more than kstones from the table. The winner is the one to take the last stone.

Here we consider a variation of this game. The number of stones that can be removed in a single move must be a member of a certain set of m numbers. Among the m numbers there is always 1 and thus the game never stalls.

Input

The input consists of a number of lines. Each line describes one game by a sequence of positive numbers. The first number is n <= 1000000 the number of stones on the table; the second number is m <= 10 giving the number of numbers that follow; the last m numbers on the line specify how many stones can be removed from the table in a single move.

Input

For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly.

Sample input

20 3 1 3 821 3 1 3 822 3 1 3 823 3 1 3 81000000 10 1 23 38 11 7 5 4 8 3 13999996 10 1 23 38 11 7 5 4 8 3 13

Output for sample input

Stan winsStan winsOllie winsStan winsStan winsOllie wins


题意   给你n个小石头  和一个数组a[m]   然后两个人轮流取石头  stan先取  olive后取  他们都完美发挥    谁取完最后一个石头谁就是赢家

感觉不是很容易看出来是dp题  令d[i]表示只有i个石子时谁赢   1表示stan赢  0表示olive赢   

i-a[j]表示从i个石子一次取走a[j]个还剩下的    所以有  当(i-a[j]>0&&d[i-a[j]]=0)是   d[i]=1; 


#include<cstdio>#include<cstring>using namespace std;int d[1000005],a[12],ans,n,m;int main(){    while(scanf("%d",&n)!=EOF)    {        scanf("%d",&m);        for(int i=1;i<=m;++i)                scanf("%d",&a[i]);        memset(d,0,sizeof(d));        for(int i=1;i<=n;++i)            for(int j=1;j<=m;++j)            {                if(i-a[j]>=0&&d[i-a[j]]==0)                {                    d[i]=1;                    break;                }            }        printf(d[n]?"Stan wins\n":"Ollie wins\n");    }}




0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小米4不充电了怎么办 小米2开不开机怎么办 手机开机键开不了机怎么办 三星s4反复重启怎么办 小米5反复重启怎么办 电脑系统奔溃了怎么办 电脑开机后屏幕出现英文怎么办 小米4开不开机了怎么办 小米4一直显示mi怎么办 小米手机开关键失灵怎么办 小米手机开机键失灵怎么办 小米6不断重启怎么办 小米6一直重启怎么办 小米6自动重启怎么办 手机的开机键坏了怎么办 小米6频繁重启怎么办 小米6安装xp卡米怎么办 刷机失败反复重启怎么办 红米手机很卡怎么办啊 红米2a显示图标怎么办 手机一直处于开机状态怎么办 vivo手机进水开不了机怎么办 魅蓝s6锁了怎么办 pos机刷卡刷多了怎么办 红米5a开不机怎么办 魅族双亲要密码怎么办? 苹果wi-fi网速慢怎么办 腾达宽带用户名密码忘了怎么办 无线网秘密忘了怎么办 wan口设置已断开怎么办 中兴手机忘记解锁图案怎么办 u盘显示参数错误怎么办 硬盘vc加密密码忘了怎么办 软件文件移动到其他盘打不开怎么办 u盘无法复制文件怎么办 u盘大文件不能拷怎么办 abc看图打印不了怎么办 百度云大文件慢怎么办 手机视频缩略图加载失败怎么办 电脑突然卡住不动了怎么办 word文档被锁住了怎么办