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.

InputThe input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.OutputFor 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

题意:
两人博弈,给出两个数a和b,较大数减去较小数的任意倍数,结果不能小于0,将两个数任意一个数减到0的为胜者。

错误思路:

最开始我是这样想的:(a,b)->(b,a%b),算一个转移,中间可以减a/b次;(b,a%b)->(a%b,b%(a%b))需要..次。把每一个转移看成一个堆,那么每堆可以任选,就成了Nim博弈了。代码如下:

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int Xor,a,b;
while(~scanf("%d%d",&a,&b)){
if(a==&&b==) return ;
Xor=;
while(true){
if(a==||b==) break;
if(a<b) swap(a,b);
Xor=Xor^(a/b);
a=a%b;
}
if(Xor) printf("Stan wins\n");
else printf("Ollie wins\n");
} return ;
}

但是这样做是有问题的,因为Nim博弈是任选一堆的任意个,而这样转化的从前往后的堆里选任意个。所以不一样。

正确打开方式:   假设a大于b a == b.  N态 a%b == 0. N态

a >= 2*b,先手能决定谁取(b,a%b),并且知道(b,a%b)是P态还是N态.    N态

b<a<2*b, 只能 -->(b,a-b) , 然后再进行前面的判断.

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int num,a,b;
while(~scanf("%d%d",&a,&b)){
if(a==&&b==) return ;
num=;
while(true){
if(a<b) swap(a,b);
if(a%b==||b==) break;
if(a>=*b) break;
a=a%b;
num++;
}
if(num&) printf("Stan wins\n");
else printf("Ollie wins\n");
} return ;
}

HDU1525 Euclid's Game的更多相关文章

  1. hdu------(1525)Euclid's Game(博弈决策树)

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. hdu1525 Euclid&#39;s Game , 基础博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=1525 题意: 两人博弈,给出两个数a和b, 较大数减去较小数的随意倍数.结果不能小于0,将两个数随意一个数减到0 ...

  3. DU1525 Euclid's Game 博弈

    HDU1525 Euclid's Game 博弈 题意 给定两个数字 a, b. 每次只能用 较大的值 减去 较小的值的倍数, 两个人轮流进行操作, 第一个得到 0 的胜利. 分析 对于 a == b ...

  4. 基础博弈论之——简单的博弈问题【hdu1525】【Euclid‘s Game】

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=60481118 由于今天考了一道博弈的问题,我竟什 ...

  5. ZOJ1913 Euclid's Game (第一道简单的博弈题)

    题目描述: Euclid's Game Time Limit: 2 Seconds      Memory Limit: 65536 KB Two players, Stan and Ollie, p ...

  6. Euclid求最大公约数

    Euclid求最大公约数算法 #include <stdio.h> int gcd(int x,int y){ while(x!=y){ if(x>y) x=x-y; else y= ...

  7. HDU 1525 Euclid's Game 博弈

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. [poj2348]Euclid's Game(博弈论+gcd)

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

  9. HDU 1525 Euclid's Game (博弈)

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. OpenGL step to step(1)

    在窗体上绘制一个矩形,just a demo #include <GLUT/GLUT.h> void init() { glClearColor(0.0,0.0,0.0,0.0); glS ...

  2. jsp中获取spring 管理的bean(通过config)

    WebApplicationContext wac = (WebApplicationContext)config.getServletContext().getAttribute(WebApplic ...

  3. Odoo电子数据交换(EDI)

    Odoo EDI功能能在odoo实例之间交换数据,可以交换哪些数据呢? 默认支持: account.invoice 发票,含发票行 res.currency res.partner purchase. ...

  4. Eoeclient源代码分析---SlidingMenu的使用

    Eoeclient源代码分析及代码凝视 使用滑动菜单SlidingMenu,单击滑动菜单的不同选项,能够通过ViewPager和PagerIndicator显示相应的数据内容. 0  BaseSlid ...

  5. Android的logger机制分析

    分析安卓的Logger机制 一.概述 Logger机制是在Android系统中提供的一个轻量级的日志系统,这个日志系统是以驱动程序的形式在内核空间实现的,在用户空间分别提供了Java接口和C/C++接 ...

  6. linux下apache https 虚拟主机配置

    如果单纯仅仅想在数据传输时加密传输,那么ssl证书是不须要认证的,可是浏览器打开时会有警告信息.如果我们做的不是一个公众产品那么也还好啦. 例如以下是今天学习时的一个笔记,事实上我用的是真实环境. 环 ...

  7. 基于multiprocessing和threading实现非阻塞的GUI界面显示

    ========================================================= 环境:python2.7.pyqt4.eric16.11 热点:multiproce ...

  8. numpy函数库中一些经常使用函数的记录

    ##numpy函数库中一些经常使用函数的记录 近期才開始接触python,python中为我们提供了大量的库,不太熟悉.因此在<机器学习实战>的学习中,对遇到的一些函数的使用方法进行记录. ...

  9. 怎么理解RSA算法

    原文地址:http://www.ittenyear.com/414/rsa/ 怎么理解RSA算法 能够把非对称加密算法里的公钥想象成一个带锁的箱子,把私钥想象成一把钥匙 能够把对称加密算法里的密钥想象 ...

  10. CentOS 7 yum安装路径查询方法

    先执行下面的命令,查看所有的已安装软件名称. rpm -qa 然后执行 rpm -ql 软件名称 就可以显示软件的安装路径.