题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1525

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

题意:

两个人,两堆石头,玩游戏。每次从石头数多的那堆中拿走石头数少的那堆石头的个数的倍数个,保证拿了过后不能为负数。谁恰好使其中一堆石头数为0,谁使其中某一堆石头为0,谁赢。两人都足够聪明。

思路:

借助欧几里得算法的博弈。

显然如果a>b 且a>2*b  先拿者必赢 因为他可以决定是自己还是对手遇到状态(a%b,b)如果状态(a%b,b)为必输状态,他就让对手面对(拿走a-a%b个)。如果为必赢状态,他就自己面对(拿走-a%b-b个).

如果b<a<=2*b 只能到达(a%b,b)的状态。

#include<iostream>
#include<cstdio>
#define ll __int64using namespace std;int gcd(ll a,ll b)
{if(a<b) //求出谁大swap(a,b);if(b==0) //终止 必输状态return 0;if(a>2*b) //必胜return 1;return gcd(b,a%b)^1; //和拿了之后的输赢情况相反
}int main()
{ll a,b;while(scanf("%I64d%I64d",&a,&b)!=EOF && a+b){int ans=gcd(a,b);if(ans)printf("Stan wins\n");elseprintf("Ollie wins\n");}return 0;
}

HD 1525 Euclid's Game相关推荐

  1. hdu 1525 Euclid‘s Game

    hdu 1525 文章目录 Problem Description 题意: 题解: 代码: Problem Description Two players, Stan and Ollie, play, ...

  2. HDU 1525 - Euclid's Game ( 博弈 )

    题意 Stan和Ollie玩游戏,Stan先手.给出两个数字,可以用大数减去小数的整数倍,要求不能减到小于0.谁先将一个数字减到0,谁获胜. 思路 博弈 假设 a > b 比赛的时候想到了关于a ...

  3. HDU 1525 Euclid's Game

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

  4. 一起开心2020暑假训练第一周

    hdu 1576 A/B oj传送 题解: Poj 1061 青蛙的约会 oj传送 题解: hdu 1525 Euclid's Game oj传送 题解: Poj 3070 Fibonacci oj传 ...

  5. 【 HDU - 1525 】Euclid's Game(较难找规律,玄学博弈,分析必败点必胜点)

    题干: Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, su ...

  6. hd disk / HDD / SSD / USB / FireWire(1394) / eSATA / SATA / mSATA / NGFF

    MBR 主启动记录 / GPT GUID分区表 注意:所有早起版本的Windows不识别GPT分区形式. 建议在大于2TB的磁盘或基于Itanium的计算机所用的磁盘上使用这种分区形式. 硬盘厂商 h ...

  7. H.265 HD 和H.265 4K Video Encoder IP Core

    H.265 HD 和H.265 4K Video Encoder IP Core H.265 HD Video Encoder IP Core(H.265 HD Video/Audio Encoder ...

  8. 开源工程系列之讯飞VBOX改装蓝牙5.0(aptX HD)音箱

    最近得到一个小度智能音箱,功能还不错,但是音效一般.想起了吃灰的讯飞VBOX,音效相当棒,只是APP和服务器已经不再维护,只能放里面自带的歌曲,遂决定改装VBOX为蓝牙音箱,使用aptX HD(CSR ...

  9. 【iOS-cocos2d-X 游戏开发之十六】Cocos2dx编译后的Android自动使用(-hd)高清图设置自适应屏幕...

    本篇主要介绍Cocos2dx项目开发过程中或者说项目务必遇到的一些知识点(ps.貌似Himi博客写的都是务必的 :tx:  Himi认为写别人没写的才更容易吸引人不是-) OK,不多说废话,第一个介绍 ...

最新文章

  1. vue.js循环for(列表渲染)详解
  2. Redis整合Spring Data Redis 开发key和value乱码
  3. 软件工程第二次作业——模仿主流网站:搜狗输入法
  4. asp.net 解码gb2312下urlencode后的字符串
  5. SpringBoot项目的 pom.xml第一行报错
  6. about x86 protected mode
  7. linux备份根目录与还原脚本,Shell脚本备份和还原MBR(主引导记录)
  8. fiddler4安装及使用手机抓包
  9. 零售销售数据分析案例实战
  10. 登峰造极__边界均衡生成对抗网络(BEGAN)(七)
  11. win10实现宽带转WiFi
  12. 使用AT89C51芯片实现生日快乐歌
  13. linux由浅入深学习一
  14. 2022考研资料每日更新(2021.07.25)
  15. Python | 人脸识别系统 — 活体检测
  16. Flutter中 解决自定义阿里妈妈图标一直显示不出来的问题
  17. Cesium第一次搭建环境出不来地球的问题
  18. 杰理之关于芯片复位【篇】
  19. 小说中场景的功能_场景的功能
  20. unity消消乐源码

热门文章

  1. 钜惠来袭丨神策学堂推出 SACA 四季班,留给你的时间不多了
  2. 一文解读:如何从 0 到 1 打造小程序爆款裂变
  3. SpringCloud运行时刷新数据源相关配置
  4. 智慧城市需要百姓智慧
  5. Java的对象初始化过程
  6. 在linux查看内存的大小
  7. 转:openTSDB 2.0 安装
  8. 游戏开发--开源软件11--Firefly(python 服务端分布式框架)||pygame
  9. 高性能的MySQL(5)索引策略-索引和表的维护
  10. FAT AP和FIT AP 区别 (无线篇)