Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 7   Accepted Submission(s) : 6
Problem 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
 
#include<iostream>
#include<algorithm>
using namespace std; int main()
{
int n,m;
while(cin>>n>>m)
{
if(n==0&&m==0)break;
int cnt=0;
int ans=0;
while(1)
{
if(n<m)swap(n,m);
ans=n/m;
if(ans>=2)break;
cnt++;
n%=m;
if(n==0)
{
cnt++;
break;
}
}
if(cnt%2==1)cout<<"Ollie wins"<<endl;
else cout<<"Stan wins"<<endl;;
}
return 0;
}

  

Euclid's Game的更多相关文章

  1. ZOJ1913 Euclid's Game (第一道简单的博弈题)

    题目描述: Euclid's Game Time Limit: 2 Seconds      Memory Limit: 65536 KB Two players, Stan and Ollie, p ...

  2. Euclid求最大公约数

    Euclid求最大公约数算法 #include <stdio.h> int gcd(int x,int y){ while(x!=y){ if(x>y) x=x-y; else y= ...

  3. HDU 1525 Euclid's Game 博弈

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. [poj2348]Euclid's Game(博弈论+gcd)

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

  5. hdu------(1525)Euclid's Game(博弈决策树)

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. HDU 1525 Euclid's Game (博弈)

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. 最大公约数与欧几里得(Euclid)算法

    ---恢复内容开始--- 记a, b的最大公约数为gcd(a, b).显然, gcd(a,b)=gcd(|a|,|b|). 计算最大公约数的Euclid算法基于下面定理: [GCD递归定理]对于任意非 ...

  8. 求两个数的最大公约数(Euclid算法)

    求两个数 p 和 q 的最大公约数(greatest common divisor,gcd),利用性质 如果 p > q, p 和 q 的最大公约数 = q 和 (p % q)的最大公约数. 证 ...

  9. 最大公约数(gcd):Euclid算法证明

    1个常识: 如果 a≥b 并且 b≤a,那么 a=b. 2个前提: 1)只在非负整数范围内讨论两个数 m 和 n 的最大公约数,即 m, n ∈ N. 2)0可以被任何数整除,但是0不能整除任何数,即 ...

  10. Euclid gcd规则的证明

    Euclid 规则:如果x和y都是正整数,而且x>=y,那么gcd(x,y)=gcd(x mod y, y) 假设x和y的gcd为a,那么必然有 x=a*n1 y=a*n2(gcd(n1,n2) ...

随机推荐

  1. 原生Android 注意事项

    如果要访问 互联网上的json数据的话 就要在 该目录下添加 访问的权限: <uses-permission android:name="android.permission.INTE ...

  2. Python_Mix*random模块,time模块,sys模块,os模块

    random模块 作用: 生成随机数(整数,小数,从列表中随机抽值,打乱列表顺序) 常用函数: random.random( )生成随机小数 random.uniform( )取一个范围之间的小数 r ...

  3. 6ci

  4. spring websocket报错:No matching message handler methods.

    错误信息: [org.springframework.web.socket.messaging.WebSocketAnnotationMethodMessageHandler]-[DEBUG] No ...

  5. 电脑小白和ta的小白电脑——JAVA开发环境

    JAVA开发环境的搭建有一点点复杂,不过一步一步来一般不会出错. (一)下载JDK 首先我们需要下载java开发工具包JDK,可以通过官网下载:http://www.oracle.com/techne ...

  6. ESP系列MQTT数据通信

    1.使用一个深圳四博智联科技有限公司的NODEMCU开发板. 2.下载MQTT的SDK压缩包,请查看附件. 3.用官方提供的Eclipse打开MQTT的sdk开发包. 4.打开include文件夹中的 ...

  7. Excel身份证验证,身份证校验公式

    =IF(LEN(Q4)=0,"空",IF(LEN(Q4)=15,"老号",IF(LEN(Q4)<>18,"位数不对",IF(CH ...

  8. Mac下安装Fiddler

    Mac下安装Fiddler 1.Mono安装 安装程序可以从http://www.mono-project.com/download地址下载. 安装完成后,打开Terminal终端,在terminal ...

  9. 目标检测(一) R-CNN

    R-CNN全称为 Region-CNN,它是第一个成功地将深度学习应用到目标检测的算法,后续的改进算法 Fast R-CNN.Faster R-CNN都是基于该算法. 传统方法 VS R-CNN 传统 ...

  10. OpenGL中VA,VAO,VBO和EBO的区别

    1,顶点数组(Vertex Array) VA,顶点数组也是收集好所有的顶点,一次性发送给GPU.不过数据不是存储于GPU中的,绘制速度上没有显示列表快,优点是可以修改数据. 4.VBO(Vertex ...