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 思路:一开始考虑PN状态是否跟奇偶有关,举出反例后pass,那么就找规律,x 0的状态是P状态,可以确定N状态为 x y (y%x=0),那么当y>=2*x时就可以判断状态,y==2*x时,一定是N状态,y>2*x时,先手可以判断y%x x是否为必败态,若y%x x为必败态,先手就将该状态转移给后手,否则,先手就将y%x+x x转移给后手,后手一定只能把y%x x转移给先手,先手必胜,也就是说,当y>=2*x时,先手就掌握了比赛,是必胜态
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; void run_case() {
int n, m;
while(cin >> n >> m && n + m) {
int win = ;
if(n < m) swap(n, m);
while(m) {
if(n%m == || (n / m) > ) break;
n -= m;
swap(n, m);
win ^= ;
}
if(win) cout << "Stan wins\n";
else cout << "Ollie wins\n";
}
} int main() {
ios::sync_with_stdio(false), cin.tie();
//int t; cin >> t;
//while(t--)
run_case();
cout.flush();
return ;
}
												

Day11 - H - Euclid's Game HDU - 1525的更多相关文章

  1. HDU 1525 类Bash博弈

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

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

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

  3. HDU 1525 Euclid's Game 博弈

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

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

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

  5. hdu 1525 Euclid's Game 博弈论

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

  6. HDU 1525 Euclid's Game

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

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

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

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

    感觉这道题用PN大法好像不顶用了,可耻地看了题解. 考虑一下简单的必胜状态,某一个数是另一个数的倍数的时候是必胜状态. 从这个角度考虑一下:游戏进行了奇数步还是偶数步决定了哪一方赢. 如果b > ...

  9. HDU 1525 Euclid Game

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

随机推荐

  1. Java进阶学习(2)之对象交互(上)

    对象交互 对象交互 对象的识别 时钟小程序 把现实世界用对象去建模,去分解问题规模,最终抽象成对象和对象的模型 例如11:03的小程序,可以抽象成一个显示类,一个类生成两个对象去表示时钟 packag ...

  2. ${var}与$var的区别,个人总结的看法

    ${var}  set variable 123 ${var}类似于变量值,相当于123 $var类似于变量名,指向对应的存储位置,相当于“123”,一般只有在rf关键字为断言的如“should be ...

  3. auto的用法

    用法参考链接:https://blog.csdn.net/arrowyl/article/details/80886515 Codeblocks 出现'auto' changes meaning in ...

  4. Linux内核5.6亮点

    导读 当我们还在体验 Linux 5.5 稳定发行版带来更好的硬件支持时,Linux 5.6 已经来了.我将在本文中重点介绍 Linux 5.6 发布版中值得期待的关键更改和功能. 说实话,Linux ...

  5. 数据库中的null,踩坑笔记

    问题来源:查询表中,complete_type 不为2的数据. 我的想法:select * from 表名 where complete_type != '2'  (除了第2条,全部显示,没问题呀) ...

  6. Educational Codeforces Round 75 (Rated for Div. 2)D(二分)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;pair<int,int>a[20 ...

  7. 安卓之滚动视图ScrollView

    (1)垂直方向滚动时,layout_width要设置为match_parent,layout_height要设置为wrap_content (2)水平方向滚动时,layout_width要设置为wra ...

  8. 数据库单,多,全库、冷热备份思路及备份与还原(mysqldump)

    热备份:服务开启状态下进行备份, 冷备份:服务关闭状态进行备份, 冷备份 数据库原有内容如下: MariaDB [(none)]> show databases;+--------------- ...

  9. python3+requests+BeautifulSoup+mysql爬取豆瓣电影top250

    基础页面:https://movie.douban.com/top250 代码: from time import sleep from requests import get from bs4 im ...

  10. try catch和if else

    当错误发生时,当事情出问题时,JavaScript 引擎通常会停止,并生成一个错误消息.描述这种情况的技术术语是:JavaScript 将抛出一个错误. try 语句允许我们定义在执行时进行错误测试的 ...