Euclid's Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1256    Accepted Submission(s): 576

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
 
Source
 
Recommend
LL
 

题目给出了两个正数a.b

每次操作,大的数减掉小的数的整数倍。一个数变为0 的时候结束。

谁先先把其中一个数减为0的获胜。问谁可以赢。Stan是先手。

假设两个数为a,b(a>=b)

如果a==b.那么肯定是先手获胜。一步就可以减为0,b

如果a%b==0.就是a是b的倍数,那么也是先手获胜。

如果a>=2*b.  那么 那个人肯定知道a%b,b是必胜态还是必败态。如果是必败态,先手将a,b变成a%b,b,那么先手肯定赢。如果是必胜态,先手将a,b变成a%b+b,b.那么对手只有将这两个数变成a%b,b,先手获胜。

如果是b<a<2*b  那么只有一条路:变成a-b,b  (这个时候0<a-b<b).这样一直下去看谁先面对上面的必胜状态。

所以假如面对b < a <2*b的状态,就先一步一步走下去。直到面对一个a%b==0 || a >=2*b的状态。

#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int a,b;
while(scanf("%d%d",&a,&b) == )
{
if( a == && b == )break;
if( a < b)swap(a,b);
int win = ;
while(b)
{
if( a%b == || a/b >= )break;
a = a-b;
swap(a,b);
win ^= ;
}
if(win == )printf("Stan wins\n");
else printf("Ollie wins\n");
}
return ;
}

HDU 1525 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. hdu 1525 Euclid's Game 博弈论

    思路:两个数a和b,总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况. 对于a/b==1这种局面, ...

  3. HDU 1525 Euclid's Game

    题目大意: 题目给出了两个正数a.b 每次操作,大的数减掉小的数的整数倍.一个数变为0 的时候结束. 谁先先把其中一个数减为0的获胜.问谁可以赢.Stan是先手. 题目思路: 无论a,b的值为多少,局 ...

  4. hdu 1525 Euclid's Game【 博弈论】

    Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtra ...

  5. HDU 1525 Euclid Game

    题目大意: 给定2个数a , b,假定b>=a总是从b中取走一个a的整数倍,也就是让 b-k*a(k*a<=b) 每人执行一步这个操作,最后得到0的人胜利结束游戏 (0,a)是一个终止态P ...

  6. HDU 1525 类Bash博弈

    给两数a,b,大的数b = b - a*k,a*k为不大于b的数,重复过程,直到一个数为0时,此时当前操作人胜. 可以发现如果每次b=b%a,那么GCD的步数决定了先手后手谁胜,而每次GCD的一步过程 ...

  7. A - 无聊的游戏 HDU - 1525(博弈)

    A - 无聊的游戏 HDU - 1525 疫情当下,有两个很无聊的人,小A和小B,准备玩一个游戏,玩法是这样的,从两个自然数开始比赛.第一个玩家小A从两个数字中的较大者减去两个数字中较小者的任何正倍数 ...

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

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

  9. HDU 1524 树上无环博弈 暴力SG

    一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...

随机推荐

  1. An AnnotationConfiguration instance is required to use

    An AnnotationConfiguration instance is required to use <mapping class="jebe7282/study/hibern ...

  2. poj 1050(DP)

    最大子矩阵和.类似于子序列最大和. // File Name: 1050.cpp // Author: Missa_Chen // Created Time: 2013年06月22日 星期六 17时0 ...

  3. jquery radio 取值 取消选中 赋值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. BZOJ 4636 蒟蒻的数列

    二分写错了血T..... 线段树标记永久化. #include<iostream> #include<cstdio> #include<cstring> #incl ...

  5. IOS中控制器的重要方法使用

    1.屏幕即将旋转的时候调用(控制器监控屏幕旋转) - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfac ...

  6. python练习程序(显示图像)

    import matplotlib as mpl import Image import numpy as np import matplotlib.pyplot as plt im=Image.op ...

  7. Linux/Unix shell 脚本中调用SQL,RMAN脚本

    Linux/Unix shell脚本中调用或执行SQL,RMAN 等为自动化作业以及多次反复执行提供了极大的便利,因此通过Linux/Unix shell来完成Oracle的相关工作,也是DBA必不可 ...

  8. android中的所谓观察者模式

    生活中我们常认定某些人很有才,但什么是有才呢?明朝的王守仁曾这样解释:才,是所谓天理,应用到物上,便成了才.凡事凡物,只要掌握了所谓科学的方法,并能灵活运用,那么你也可以成为一个有才的人. 观察者模式 ...

  9. 编译及load mydqli.so文件

    (1)cd /usr/local/php-5.2.17/ext/mysqli(2)输入/usr/local/php/bin/phpize 回车(3)./configure --prefix=/usr/ ...

  10. 《A Tour of PostgreSQL Internals》学习笔记——进程间通信

    中秋节假期这么快就没了,这几天还一直下雨,索性在家看看书.这次看的是Tom Lane的<A Tour of PostgreSQL Internals>.这篇小随笔就算做学习笔记了.园子里面 ...