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
------------------------------------------------------------------
题意:两个人在玩一个类似gcd的游戏,从两个数中不断用较大数中减去较小数的倍数,谁先得到0谁获胜,问谁赢。
分析:一开始还以为是要跑gcd,然而还是太naive了。看了一下《挑战》,总结了一下思路。
  {策略1}:对于(a,b)(a>b)来说,如果a是b的倍数,那么肯定当前者赢。
  {策略2}:对于(a,b)(a>b)来说,如果a<2*b,那么意味着下一个状态必定是(b,a-b),因为此时a不可能减去更多倍的b,以此类推之后,永远不会出现a%b==0的情况,因为如果能出现的话,策略1就会将其判定了。那么肯定当前者赢。
  用上策略1和策略2就AC了。
 #include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
long long a,b;//f=1表示stan赢
while( scanf("%lld%lld",&a,&b)== && a!= && b!= )
{
int f=;
while()
{
if(a>b) swap(a,b);
if(b%a==) break;//策略1
if(b-a>a) break;//策略2
b-=a;
f*=-;
}
if(f==) printf("Stan wins\n");
else printf("Ollie wins\n");
}
return ;
}

【POJ】2348 Euclid's Game(扩欧)的更多相关文章

  1. poj 2348 Euclid's Game 题解

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9023   Accepted: 3691 Des ...

  2. POJ 2348 Euclid's Game(辗转相除博弈+自由度分析)

    题目链接:http://poj.org/problem?id=2348 题目大意:给你两个数a,b,Stan和Ollie轮流操作,每次可以将较大的数减去较小的数的整数倍,相减后结果不能小于0,谁先将其 ...

  3. POJ 2348 Euclid's Game 博弈论

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

  4. POJ 2348 Euclid's Game(博弈论)

    [题目链接] http://poj.org/problem?id=2348 [题目大意] 给出两个数,两个参赛者轮流用一个数减去另一个数的倍数,当一个数为0的时候游戏获胜, 求先手是否必胜 [题解] ...

  5. POJ 2348 Euclid's Game【博弈】

    题目链接: http://poj.org/problem?id=2348 题意: 给定两个数,两个人每次从较大数中减去较小数的倍数,谁先得到0谁获胜,为谁赢? 分析: 令一种可能出现的整数对为(a,b ...

  6. POJ 2348 Euclid's Game(博弈)题解

    题意:有a,b两个数字,两人轮流操作,每次可以选择两个之中较小的数字,然后另一个数字减去选择数字的任意倍数(不能减到负数),直到其中一个为0,不能操作为败 思路:这题用博弈NP思想,必败点和必胜点之间 ...

  7. POJ 2348 Euclid Game (模拟题)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7942   Accepted: 3227 Des ...

  8. POJ 2348 Euclid's Game(简单博弈)

    这道题没说a b最大多少,所以要声明为long long型,不然会WA! 道理很简单,(默认a>=b)a和b只有以下三种关系: 1.a%b==0 :这种关系下,可能是a/b为整数,也可能是a和b ...

  9. poj 2348 Euclid's Game

    题目: 给两个整数a和b,两个人先后用较大的数减去较小数的整数倍,并且保证相减后为非负数.先把一个数变为0的人获胜. 分析: 很显然,当大数是小数的整数倍时为必胜态. 从这道题学会一个叫做自由度的东西 ...

  10. POJ 2348 Euclid's Game (博弈)

    题意:给定两个整数,两个人轮流操作,每次可以用较大数减去较小数的整数倍,当一个数变成0时,则结束,问谁会胜. 析:很明显如果 a == b 那么就可以直接结束了,那么如果 a > b我们可以交换 ...

随机推荐

  1. js动态获取时间的方式

    列子的时间是这样实现的."2017/7/25 下午10:27:11 星期二" 列子中有一个div用来放时间. 每隔1s执行一次函数,秒就会变. function showTime( ...

  2. [js高手之路]javascript腾讯面试题学习封装一个简易的异步队列

    这道js的面试题,是这样的,页面上有一个按钮,一个ul,点击按钮的时候,每隔1秒钟向ul的后面追加一个li, 一共追加10个,li的内容从0开始技术( 0, 1, 2, ....9 ),首先我们用闭包 ...

  3. sed修炼系列(三):sed高级应用之实现窗口滑动技术

    html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...

  4. 三、nginx实现反向代理负载均衡

    1.反向代理 需求: 两个tomcat服务通过nginx反向代理 nginx服务器:192.168.101.3 tomcat1服务器:192.168.101.5 tomcat2服务器:192.168. ...

  5. Prism for Xamarin.Forms

    一.使用环境 OS:Win 10 16273 VS:VS2017- 15.3.4 Xamarin:4.6.3.4,nuget:2.4 Android Emulator:Visual Studio fo ...

  6. Winform控件输入的字母转换成大写

    private void textBoxHbh_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 'a' & ...

  7. Mac环境下mysql初始化密码问题--If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.

    个人在Mac上操作数据库,遇到的启动数据库问题的简单记录 1.苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) 2.进 ...

  8. 将home多余的空间分配到"/"分区下

    一.操作过程 1.df -h 查看分区大小情况; [root@localhost /]# df -h Filesystem            Size  Used Avail Use% Mount ...

  9. 超级简单实用的前端必备技能-javascript-全屏滚动插件

      fullPage.js fullPage.js是一个基于jQuery的全屏滚动插件,它能够很方便.很轻松的制作出全屏网站 本章内容将详细介绍Android事件的具体处理及常见事件. 主要功能 支持 ...

  10. 201521123055 《Java程序设计》第9周学习总结

    1. 本章学习总结 2. 书面作业 Q.1常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免? 1.3 什么样的 ...