hdu 1525

文章目录

  • Problem Description
  • 题意:
  • 题解:
  • 代码:

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

题意:

n和m两个数,两个人轮流进行操作,每次可以剪去i*min(n,m),i自定(剪去n和m中最小数的倍数),有一个数减到0即为胜利,问先手后手谁先赢

题解:

非正式解答:
一看是博弈论我就开始搜索我脑中的知识(发现为空)
直觉告诉我肯定有规律和公式,我便自造数据多次实验,最终发现最先遇到一个数是另一个数的两倍以上时,即可以成功(也就是(n/m>1),此处n>m),特殊情况是n和m相同时也是谁遇到谁赢。综合下就是:谁遇到n/m!=1时,谁就赢。
为什么呢?我是这么理解的,当遇到n/m>1时,此人可以选择减一个m,也可以选减多个m,而这对后面的情况是有影响的,而总有一种情况是对自己有利的,只要按照这个方向走,一定能赢(多局试验后得出)
当然如果全程n/m==1,那么双方的操作都是固定的,没有选择空间,因为都只能减一次,所以轮流操作,奇数个操作流程先手赢,反之后手赢
正式解答:
正规解答来自
令n为较小的数,m为较大的数,可以发现:
当m%n=0时,先手必胜

当m>=2n时,如果(m%n,m)为必胜态,先手可以先将局势变为(m%n+n,n),则后手只能将局势变为(m%n,n);如果(m%n,n)为必败态,先手可以直接将局势变为(m%n,n)。因此,不论(m%n,n)为什么态,先手都必胜

当2n>m>n时,那就是一步一步走下去,直到出现m%n=0||m>=2n结束

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{int n,m;while(cin>>n>>m){if(n==0&&m==0)break;if(m>n)swap(n,m);int ans=1;//记录步伐int f=-1;while(n!=0&&m!=0){if(m>n)swap(n,m);if(n/m!=1||m==0){f=ans;break;}ans++;n-=m;}if(f&1)cout<<"Stan wins"<<endl;else cout<<"Ollie wins"<<endl;}return 0;
}

hdu 1525 Euclid‘s Game相关推荐

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

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

  2. HDU 1525 Euclid's Game

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

  3. HDU 1525 类Bash博弈

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

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

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

  5. HD 1525 Euclid's Game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1525 Problem Description Two players, Stan and Ollie, ...

  6. HDU - 1525

    题意:给你两个数,a,b,有两个人轮流进行一次操作, 每次操作可以将大的数减去k倍的小的数,最后不能操作的人输了,问你谁赢了. 思路:我们可以用辗转相除法求出对于每一个状态可以改变几次,这样问题就变成 ...

  7. hdu 1525 博弈

    欧几里德问题上的博弈,理解后不难. /* * hdu1525/win.cpp * Created on: 2011-11-11 * Author : ben*/#include <cstdio& ...

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

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

  9. [kuangbin]各种各样的题单

    [kuangbin]各种各样的题单 专题1 简单搜索 POJ 1321 POJ 2251 POJ 3278 POJ 3279 POJ 1426 POJ 3126 POJ 3087 POJ 3414 F ...

最新文章

  1. linux备份svn仓库脚本,Centos详细搭建svn以及备份脚本
  2. 2020年港澳台电视直播软件_中山大学2020年港澳台侨联考各专业录取分数线
  3. USB hub(221)
  4. 借助Fiddle使用不同版本的UI5库文件进行测试
  5. android 调出键盘表情_Android 软键盘和emoji表情切换方案,和微信几乎一样的体验...
  6. 祝福!微软 46 周年生日快乐!
  7. 一个mysql复制中断的案例
  8. 应用开发专家一席谈:开发低代码,上手低门槛,AppCube使能Citizen Developer,人人都是开发者
  9. 重新配置Domino服务器
  10. EasyRecovery——一款专业的数据恢复软件
  11. c语言 期末,c语言期末 求助
  12. Norton AntiVirus (诺顿杀毒)v9.0 简体中文企业版
  13. 五分钟学会做一个在线抽奖系统,手把手教你抽奖还学不会嘛?
  14. 前端分页加载功能实现?
  15. 苹果怎么用测试软件,iPhone 也能测量身高教你怎么用 iOS「测距仪」App
  16. python matplotlib绘图同时支持宋体和timesnewroman
  17. 计算机关机快捷图标,七大电脑关机快捷方式,知道3种以上都是大神!
  18. 申论中关于人物“精神”、“品质”的总结
  19. JAVA--Socket【“套接字”】
  20. MySQL数据库全量、增量备份与恢复

热门文章

  1. 《Pyflink》Flink集群安装,Python+Flink调研
  2. 输出毫秒_自学单片机第十三篇上:单点输出
  3. 元胞自动机模型_【ABM仿真模拟】第三章 元胞自动机 B
  4. shell grep 变量_老司机给出的关于 shell 脚本的8个建议,必收!
  5. linux图形界面鼠标变成小手_加载Linux系统,树莓派变身桌面电脑
  6. 超详细图解!【MySQL进阶篇】MySQL索引原理
  7. php实现电脑自动关机,用批处理实现电脑自动关机
  8. c语言铁路托运行李费用图,3.为铁路部门编写计算运费的程序。假设铁路托运行李,规定每张客票托运费计算方法是:行李重量不超过50kg...
  9. 机器学习——文件的读取
  10. 软件构造学习笔记-第八周