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

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

Source

[Submit]   [Go Back]   [Status]   [Discuss]

————————————————————————我是分割线——————————————————————————

博弈论题目。

第一眼看见我竟以为是nim游戏 TAT~

其实当n/m>=2时即为关键点,此时关键点掌控方可以决定游戏胜败。

所以判断谁掌握关键点即可。

 /*
Problem:
OJ:
User: S.B.S.
Time:
Memory:
Length:
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#include<functional>
#include<bitset>
#include<vector>
#include<list>
#include<map>
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define maxn 10001
#define inf 0x3f3f3f3f
#define maxm 1001
#define mod 998244353
//#define LOCAL
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m;
inline int gcd(int a,int b)
{
return b ? gcd(b,a%b) : a;
}
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
#ifdef LOCAL
freopen("coin.in","r",stdin);
freopen("coin.out","w",stdout);
#endif
while(cin>>n>>m&&(n!=||m!=))
{
if(n<m) swap(n,m);
if(m==) cout<<"Ollie wins"<<endl;
else if(n%m==) cout<<"Stan wins"<<endl;
else{
long long cnt=;
while(m!=&&n/m==){
cnt++;
n=n-m;swap(n,m);
}
// cout<<cnt<<endl;
if(cnt%==) cout<<"Stan wins"<<endl;
else cout<<"Ollie wins"<<endl;
}
}
return ;
}

poj 2348

poj 2348 Euclid's Game 题解的更多相关文章

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

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

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

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

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

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

  4. POJ 2348 Euclid's Game 博弈论

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

  5. POJ 2348 Euclid Game (模拟题)

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

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

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

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

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

  8. poj 2348 Euclid's Game

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

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

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

随机推荐

  1. Windows下使用 Sublime Text + MinGW 搭建C/C++开发环境

    下载并安装 Sublime Text 点击此处从官网下载适合自己的Windows系统的Sublime Text 下载好后双击进行安装(一路next就好啦) 下载 MinGW 点击此处下载MinGW 下 ...

  2. java 线程池(ExecutorService与Spring配置threadPoolTaskExecutor)

    一.java ExecutorService实现 创建ExecutorService变量private ExecutorService executor = null 2.执行对应任务时,首先生成线程 ...

  3. 日志回滚:python(日志分割)

    日志回滚:python 什么是日志回滚? 答: 将日志信息输出到一个单一的文件中,随着应用程序的持续使用,该日志文件会越来越庞大,进而影响系统的性能.因此,有必要对日志文件按某种条件进行切分,要切分日 ...

  4. MySQL主从检验一致性工具pt-table-checksum报错的案例分析

    [问题] 有同事反馈我们改造过的MySQL5.7.23版本,使用pt-table-checksum工具比较主从数据库的一致性时报错 Unsafe statement written to the bi ...

  5. php模板引擎之featherview

    在纯php文件中不加php结束符是一个好习惯,php结束符仅用于在php与html混写时标示php代码结束. <? ?>是短标签,<?php ?>是长标签,在php的配置文件( ...

  6. HTTP协议-MIME类型

    每一个 URL 都代表着一个资源对象,而当我们请求一个网页的时候,看似只请求了一个 URI(统一资源标识符),实际上这个网页可能包含多个 URI,例如图片资源的 URI 和视频资源的 URI 等.此时 ...

  7. hdu 5203 && BC Round #37 1002

    代码参考自:xyz111 题意: 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的:勇太有一根长度为n的木棍,这个木棍是由n个长度为1的小木棍拼接而成,当然由于时间 ...

  8. (转载)Spring 注解@Component,@Service,@Controller,@Repository

    Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository.@Service 和 @Controller.在目前的 Spring ...

  9. [Deepin 15] 编译安装 PHP-5.6.30

    先看下历史笔记: Ubuntu 14 编译安装 PHP 5.4.45 + Nginx 1.4.7 + MySQL 5.6.26 笔记 ################################# ...

  10. mac 刻录ISO系统盘

    今天本本系统坏了,手头上又没有U盘PE工具,只有MAC和光驱,只好在MAC上下载系统ISO刻录,我是直接点ISO文件,右键刻录到光盘,刻录好之后放到本本上发现不能引导,再把光盘放回MAC上一看,光盘里 ...