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. Struts2学习记录-Value Stack(值栈)和OGNL表达式

    仅仅是学习记录.把我知道的都说出来 一.值栈的作用 记录处理当前请求的action的数据. 二,小样例 有两个action:Action1和Action2 Action1有两个属性:name和pass ...

  2. Shell脚本之:变量

    与编译型语言不同,shell脚本是一种解释型语言. 执行这类程序时,解释器(interpreter)需要读取我们编写的源代码(source code),并将其转换成目标代码(object code), ...

  3. WebService中获取request对象一例

    @WebService @Service public class WeiXinWebServiceImpl implements IWeiXinWebService { @Resource priv ...

  4. iOS开发 - &quot;Cast from pointer to smaller type &#39;int&#39; loses information” 解决的方法

    今天要写一个联系人搜索算法. 百度了下, 在code4App中找到相关代码. 可是自己跑了下, 发现报错. 错误内容例如以下: "Cast from pointer to smaller t ...

  5. mysql启动參数(/etc/my.cnf)具体解释汇总

    在linux以下的/etc/my.cnf的參数具体解释汇总 MYSQL–my.cnf配置中文具体解释 basedir = path   使用给定文件夹作为根文件夹(安装文件夹). character- ...

  6. eclipse中查看java源代码设置方法

    众所周知,第一次查看class文件时,eclipse会给个界面选择添加源代码路径.   但是,如果我要换源代码路径了怎么办,eclipse也不会提示了.那就使用手动的吧       方法1: 使用ec ...

  7. Bootstrap--常用及实例合集

    栅格系统 1. row必须放到container和container-fluid里面        2. 你的内容应当放置于“列(column)”内,并且,只有“列(column)”可以作为行(row ...

  8. Java编码辅助工具:Mapstruct—— Java对象转换框架

    项目开发中,业务分层会涉及不同类型的Bean之间需要相互转换,如PO与DTO之间,PO与VO之间等.手动编码setter/getter各个对应属性,会显得臃肿繁琐.通过Mapstruct框架可简单方便 ...

  9. java中url正则regex匹配

    String regex = "^(?:https?://)?[\\w]{1,}(?:\\.?[\\w]{1,})+[\\w-_/?&=#%:]*$"; 解释说明: ^ : ...

  10. 杂谈:HTML 5的消息通知机制

    译文来源:http://www.ido321.com/1130.html 原文:HTML 5 Notification 译文:HTML 5 的消息通知机制 译者:dwqs watermark/2/te ...