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

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 可以参考:《基础训练题解》哈尔滨出版社 俞经善...等编

题意讲解:两个人Ollie和Stan玩一个游戏,每次输入两个非负数。 Stan为先手,Ollie为后手。
每次从大数中减去小数的任意倍数,将其减完后的结果赋值给被减的大数。Ollie刚才的游戏规则,
然后进行循环。直到小数不能再大数中拿到一个非0的数为止。最后一个拿到数的玩家为赢家。 算法讲解:大数除以小数,当值大于1时,正在进行此次游戏的玩家为赢家。否则要继续游戏。
当游戏进行了偶数次的时候,就是Stan赢,否则就是Ollie赢了。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm> using namespace std; int main()
{
int x, y;
while(scanf("%d %d", &x, &y)!=EOF)
{
if(x==0 && y==0) break; int dd;
int cnt=0; //记录游戏进行次数
int n=x; int m=y;
while(n!=0 && m!=0 )
{
if(m>n){
cnt++;
dd = m/n;
m=m%n; //大数被赋值成那个差值
if(dd >= 2) break;
}
else{
cnt++;
dd=n/m;
n=n%m;
if(dd>=2 ) break;
}
}
if(cnt%2==1) printf("Stan wins\n");
else
printf("Ollie wins\n");
}
return 0;
}


POJ 2348 Euclid Game (模拟题)的更多相关文章

  1. poj 2348 Euclid's Game 题解

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

  2. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  3. POJ - 1835 宇航员(模拟题)

    问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...

  4. POJ 2348 Euclid's Game 博弈论

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Mockito 如何 mock 返回值为 void 的方法

    转载:https://unmi.cc/mockito-how-to-mock-void-method/#more-7748 最初接触 Mockito 还思考并尝试过如何用它来 mock 返回值为 vo ...

  2. 4pda.ru注冊验证的解码算法

    代码源于看雪林版在我群里介绍注冊一个俄文安卓论坛.发出来了链接大家在測试注冊. http://4pda.ru/forum/index.php? 註册方式請参看: _https://forum.tuts ...

  3. Vue.js 很好,但会比 Angular 或 React 更好吗?

    文章转自:http://www.oschina.net/translate/vuejs-is-good-but-is-it-better-than-angular-or-rea Vue.js 是一个用 ...

  4. Linux禁止Ctrl+Alt+Del重新启动

    方法1:改动/etc/inittab 屏蔽 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now 或者删除改行内容 保存退出 适用对象:RedHat4.8 ...

  5. redis远程登录

    #redis-cli -h 202.96.126.37 -p 6379 #auth 'd6d72fa9b2ff458e:GRjZmQ3MTN'

  6. 栈(C++)

    简介: 限定仅在表尾进行插入或删除操作的线性表 表尾端称为栈顶(top),表头端称为栈底(bottom) 特点: 在栈中,后入栈的元素先出栈 C语言版本 用于测试的文件,以及测试结果可以去作者GitH ...

  7. Hollis原创|不了解这12个语法糖,别说你会Java

    GitHub 2.5k Star 的Java工程师成神之路 ,不来了解一下吗? GitHub 2.5k Star 的Java工程师成神之路 ,真的不来了解一下吗? GitHub 2.5k Star 的 ...

  8. anaconda2下面安装opencv2.4.13.4完成----解决默认安装的问题----Thefunction is not implemented. Rebuild the library with Windows, GTK+ 2.x orCarbon support. If you are on Ubuntu or Debian, install libgtk2.0‑dev and pkg

    转载自:http://blog.csdn.net/qingyanyichen/article/details/73550924 本人下载编译安装了opencv2.4.9,oppencv2.4.10,o ...

  9. java提高同步锁的几点建议

    1.减少锁的持有时间,只对关键的代码块加锁,减少synchronized锁内部的无关模块: 2.减小锁粒度,如Collections.synchronizedMap(map)返回线程安全的map会锁整 ...

  10. MySQL技术内幕InnoDB存储引擎(表&索引算法和锁)

    表 4.1.innodb存储引擎表类型 innodb表类似oracle的IOT表(索引聚集表-indexorganized table),在innodb表中每张表都会有一个主键,如果在创建表时没有显示 ...