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. 关于node_js的比较

    node_js的比较是我自己初学遇到的第一个绕脑的事情. 在比较的函数多了之后,一些函数的调用和变量提升, 搞得自己头晕,有时候函数是没有返回值的,自己还在 用变量值去比较,实际上却是undefine ...

  2. HTML的块级元素和行内元素

    行内元素一般是内容的容器,而块级元素一般是其他容器的容器.一般情况下,行内元素只能包含内容或者其它行内元素,宽度和长度依据内容而定,不可以设置,可以和其它元素和平共处于一行:而块级元素可以包含行内元素 ...

  3. PyCharm for windows 快捷功能(图片形式讲解)

  4. Python爬虫——西刺

    一直对爬虫这块蛮感兴趣的,所以花了点时间看了看,写了个小脚本 代码可能有点乱,毕竟Python小白,勿喷…… 嗯,话不多说,放码出来 # -*- coding: UTF-8 -*- import re ...

  5. SSM搭建遇到的坑

    1,Error:(6, 24) java: package org.junit.runner does not exist 错误原因: 当时傻傻的把zl 包(单元测试包)放在了src/main/jav ...

  6. java 初学 英语单词 记录在此 希望全部记住

    Java英文单词Java基础常见英语词汇(共70个)                                                                          ...

  7. Linux常见命令快捷方式

    命令行编辑的辅助操作: Tab健:自动补齐 Ctrl +U :清空至首行 Ctrl +K:  清空至尾行 Ctrl +L:(或者clear) 清屏 Ctrl +C:  取消执行命令 获取帮助命令: 内 ...

  8. 信息技术手册可视化进度报告 基于jieba的关键字提取技术

    在这一篇博客之前,我已经将word文件中的内容通过爬虫的方式整理到数据库中了,但是为了前台展示的需要,还必须提取出关键字,用于检索. 我用的是jieba分词,GitHub地址:https://gith ...

  9. DAY4:简单购物系统

    根据前几天对于循环和列表的学习,做了一个简单的购物系统: 密码模块就是前篇文章已经做过就,直接调用过来就行,简单说一下该购物系统功能 1,展示货物,需要手动添加,haha 2,判断余额是否充足并充值 ...

  10. java 五十条数据分为一组

    public static void main(String[] args) { List<Integer> list = new ArrayList<>(); for(int ...