Euclid's Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9033   Accepted: 3695

Description

Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser of the two numbers from the greater of the two numbers, provided that the resulting number must be nonnegative. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7):

         25 7

11 7

4 7

4 3

1 3

1 0

an Stan wins.

Input

The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.

Output

For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly. The last line of input contains two zeroes and should not be processed.

Sample Input

34 12
15 24
0 0

Sample Output

Stan wins
Ollie wins

Source

 
 
老师的惊天模拟赛#1
 
TAT我天真的以为我会这道题了
很容易想到对于两堆数字,只有两种决策:拿一个或者拿多个
对于a>b且a<2*b的情况,只能拿一种,因此可以确定先后手
当可以拿多次时,要么全取走能取走的,要么再留下一次能取的量
所以对两个数做一次gcd
每次取模前判断可以取几次数字,得到一个序列仅包含1和2
(我只想到这里)
(话说讲博弈论的时候我好像睡着了怪不得)
对于连续的1,可以立刻判断结尾先手还是后手
但对于一个2,只要有一方遇到了2,他就可以操纵局势
即在2结束后,他一定可以让自己位于序列结尾或下一个2
那么在gcd的时候,只需记录出现第一个2的时候是先手还是后手即可
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define LL long long
int main(){
int tmp,n,m,pl;
while(scanf("%d %d",&n,&m)!=EOF&&(n&&m)){
pl=;
while(n&&m){
if(m<n){tmp=m;m=n;n=tmp;}
if((n<<)>&&m>=(n<<))break;
m=m%n;
if(!m)break;
pl^=;
}
if(!pl)puts("Stan wins");
else puts("Ollie wins");
}
return ;
}

[poj2348]Euclid's Game(博弈论+gcd)的更多相关文章

  1. 【博弈论】poj2348 Euclid's Game

    假设当前b>a. 一.b%a==0 必胜 二.b<2*a,当前我们没有选择的余地,若下一步是必胜(最终能到情况一),则当前必败:反之,当前必胜. 三.b>2*a,假设x是使得b-ax ...

  2. POJ 2348 Euclid's Game 博弈论

    http://poj.org/problem?id=2348 顺便说,必应翻译真的好用,比谷歌翻译好用100倍. 很难判断这道题的具体博弈类型. 有两种写法,一种是找规律,一种是推理得到关系后循环(或 ...

  3. hdu 1525 Euclid's Game 博弈论

    思路:两个数a和b,总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况. 对于a/b==1这种局面, ...

  4. [POJ2348]Euclid's Game

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8313   Accepted: 3374 Description Two p ...

  5. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  6. Design and Analysis of Algorithms_Introduction

    I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...

  7. C#读取图片Exif信息

    Exif是可交换图像文件的缩写,是专门为数码相机的照片设定的,可以记录数码照片的属性和拍摄数据 ////调用 //string strFile="fffff.jpg";//文件名 ...

  8. C++基础学习教程(五)

    这一讲我们集中解说类和他的一些特性.首先我们从自己定义一个有理数类来開始. 在C语言中有一个keyword: struct ,用来创建一个结构体类型.可是在C++中这个关键的含义就不只如此了,以下我们 ...

  9. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

随机推荐

  1. C#下没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))

    C#下没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)) 原因:没有原生支持64位,而是以32位兼容方式运行 解决办法:在项目属性里设置“生成” ...

  2. CSS中可以和不可以继承的属性

    一.无继承性的属性 1.display:规定元素应该生成的框的类型 2.文本属性: vertical-align:垂直文本对齐 text-decoration:规定添加到文本的装饰 text-shad ...

  3. [Spring常见问题]java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    这个问题是因为部署在tomcat下的项目中没有springweb包 但是问题来了,但是我的项目中有呀,maven都引了呀,然后我就懵B啦!看到这个博客我就豁然开朗了:http://my.oschina ...

  4. maven打包日志输出优化-去掉泛型与过时的警告

    pom.xml配置 1.使用eclipse编译 <!-- Eclipse编译代码时,使用的是自带的JDT(Java Development Tools), 而Maven默认使用的是JAVA_HO ...

  5. Adobe AIR对本地文件(XML文件)的操作

    引用:http://addiwang.blog.163.com/blog/static/118130772011221114230288/ Air的文件操做主要涉及两个类,FIle和FileStrea ...

  6. [ASP.NET MVC] Real-time之HTML5 服务器发送事件(server-sent event)

    最近有时间,打算看看SignalR,顺便了解一下Server Sent Events. Controller 输出的数据格式为:data:[数据]\n\n.输出的数据尝试8000多字符也没问题,具体的 ...

  7. xib加载的两种方式

      •Xib文件的加载 Ø方法1 NSArray *objs = [[NSBundle mainBundle] loadNibNamed:@"AppView" owner:nil ...

  8. clock()、time()、clock_gettime()和gettimeofday()函数的用法和区别【转】

    转自:http://www.cnblogs.com/krythur/archive/2013/02/25/2932647.html 转自http://blog.sina.com.cn/s/blog_7 ...

  9. [已解决] git 重命名文件夹

    git mv oldfolder newfolder 原文地址:http://www.cnblogs.com/gifisan/p/5980608.html

  10. 【转】解决eclipse新导入工程无法run as server

    转载地址:http://blog.csdn.net/huang86411/article/details/12118309 问题描述: 从SVN或者别处搞过来的web项目,利用eclipse工具,新建 ...