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. test--3

    <script type="text/javascript">// <![CDATA[$(function () { if (isLogined &&am ...

  2. spoj Ae2b

    题解: 设最后为x1+t1k+t2n,y1+t3k+t4n 显然t1,t4或t2,t3同余(mod 2) 然后exgcd一下 代码: #include<bits/stdc++.h> #de ...

  3. result type

    <result-types> <result-type name="chain" class="com.opensymphony.xwork2.Acti ...

  4. PHP 轻量级 REST框架

    GITHUB:https://github.com/jacwright/RestServer 简介: 一个PHP REST服务器,用于提供非常轻量级的REST API.很容易上手.独立于其他库和框架. ...

  5. jenkins 忘记用户名和密码

    有时候会经常遇到这种情况,长时间不用会遗忘用户名和密码 admin初始密码未修改的情况 进入\Jenkins\secrets目录,打开initialAdminPassword文件,复制密码: 访问Je ...

  6. 活代码LINQ——09

    一.代码 ' Fig. 9.7: LINQWithListCollection.vb ' LINQ to Objects using a List(Of String). Module LINQWit ...

  7. 泛型--增强for循环--数组和集合转换

    1:List的子类(掌握) (1)List的子类特点 ArrayList: 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector: 底层数据结构是数组,查询快,增删慢 线程安全,效率低 ...

  8. 关于mysql安装后在客户端cmd插入语句无法执行的问题

    关于mysql安装后在客户端cmd插入语句无法执行的问题 因为windows cmd默认字符集是gbk,当character_set_client=utf8时,cmd中出现中文会报错:characte ...

  9. C# WebAPI分页实现分享

    第一次分享代码,不足或不对之处请指正.. 需求:微信端传递不同的参数调用WebAPI进行分页查询菜谱计划点评结果 思路:基于视图来查询,根据传递的不同参数拼接分页查询Sql来查询. 分页的sql如下 ...

  10. spring-data-mongodb与mongo shell的对应关系

    除了特殊注释外,本文的测试结果均基于 spring-data-mongodb:1.10.6.RELEASE(spring-boot-starter:1.5.6.RELEASE),MongoDB 3.0 ...