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. javeEE第二周

    XML(可扩展标记语言) 1.什么是xml? 扩展标记语言 XML(Extensible Markup Language) 的规范定义:用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义 ...

  2. Asp .Net Core Spa (二) - 服务器渲染1

    Server Side Rendering 服务器渲染是各 Spa 项目目前很热衷于解决的一个问题,毕竟针对SEO和首次加载优化 .Net Core SPA 服务器渲染 将分为 两篇: 第一篇 主要分 ...

  3. Asp.Net Core MongoDB

    废话不说直接上代码: using MongoDB.Bson.Serialization.Attributes; namespace XL.Core.MongoDB { public interface ...

  4. SharePoint Framework 在web部件中使用第三方样式 - 将第三方样式打到包中

    博客地址:http://blog.csdn.net/FoxDave 有许多第三方库可以帮助我们构建丰富的SharePoint Framework客户端web部件.并且这些JavaScript脚本常常包 ...

  5. Ruby中方法的设计理念

    Ruby中的方法命名遵从与局部变量相同的规则和约定.这是一种设计理念:方法并不因其自身作为方法而被人关注,而是简单地作为提供值的表达式融入到程序的结构中.

  6. python基础知识总结(二)

    基础数据类型初始: int(数字):+ 加     - 减 *  乘 /  除 % 取余数 str(字符串):python中凡是用引号引起来的都是字符串 可以相加,用来表示字符串的拼接 可以相乘,只能 ...

  7. myeclipse 修改用户名密码

    当在一台公共的电脑上开发程序时,就需要涉及到更改svn用户名和密码,不然直接用本机用户密码提交,有点不妥. win7系统解决方案: C:\Documents and Settings\Administ ...

  8. Qt 文件的操作

    文件操作是应用程序必不可少的部分.Qt 作为一个通用开发库,提供了跨平台的文件操作能力.从本章开始,我们来了解下 Qt 的文件以及输入输出的功能,也就是 I/O 系统. Qt 通过QIODevice提 ...

  9. C语言关键字分类整理

    C语言总览: 强类型,面向过程 简洁.灵活:32个关键字(C99标准新增5个,C11新增7个),9种控制语句,34种运算符 数据类型丰富,运算符丰富 结构化(控制语句).模块化(函数) 灵魂.特色:指 ...

  10. 国内第一本cbuilder开发web的宝典震撼登场(delphi也可参考)

    uniGUI入门到精通cBuilder版 众所周知,cbuilder和delphi是曾经风靡多年的强悍的万能的开发工具,岂奈大浪淘沙,B/S时代的到来让这对孪生兄弟隐姓埋名.然,无数风流人物依然对他们 ...