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. What Is A Airless Pump Bottle?

    What is an airless pump bottle?Unlike conventional dispensers that use a tube or suction tube to dra ...

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

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

  3. POJ 1274 The Perfect Stall(二分图 && 匈牙利 && 最小点覆盖)

    嗯... 题目链接:http://poj.org/problem?id=1274 一道很经典的匈牙利算法的题目: 将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将 ...

  4. X86汇编指令集大全【转】

    [原文地址]https://blog.csdn.net/bjbz_cxy/article/details/79467688[原文地址] ---------- 一.数据传输指令 ------------ ...

  5. excel表格 筛选 通过mysql语句

    1.整理excel表格的数据 类似的 前面有其他符号的 都可以处理. 注意下一步是2个操纵:分别设置左右: 结果: 2.在复制粘贴到excel的时候,会有一些数字被设置成了科学计数法, 例如复制到ex ...

  6. php 用mysqli的json_encode()转换出来 全是对象的问题

    <?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/9/6 0006 * Time: 15:33 */ //查 ...

  7. 【笔记6-支付及订单模块】从0开始 独立完成企业级Java电商网站开发(服务端)

    支付模块 实际开发工作中经常会遇见如下场景,一个支付模块,一个订单模块,有一定依赖,一个同事负责支付模块,另一个同事负责订单模块,但是开发支付模块的时候要依赖订单模块的相关类 ,方法,或者工具类,这些 ...

  8. 四种常见的数据结构、LinkedList、Set集合、Collection、Map总结

    四种常见的数据结构:    1.堆栈结构:        先进后出的特点.(就像弹夹一样,先进去的在后进去的低下.)    2.队列结构:        先进先出的特点.(就像安检一样,先进去的先出来 ...

  9. 2019牛客暑期多校训练营(第七场)A String (字符串的最小表示)

    思路 这题思路如果是递归的话,应该是比较正确的.但是实际上只用切割两次就可以了. 先把原串从后向前切割一次,再把每一部分切割一次. 切两次的思路实际上是有漏洞的. 递归的思路,终点是,如果串长为1,或 ...

  10. spring boot jpa 复杂查询 动态查询 连接and和or 模糊查询 分页查询

    最近项目中用到了jpa,刚接触的时候有些激动,以前的到层忽然不用写sql不用去自己实现了,只是取个方法名就实现了,太惊艳了,惊为天人,但是慢慢的就发现不是这么回事了,在动态查询的时候,不知道怎么操作了 ...