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. 安慰奶牛Cheering up the Cow

    传送门 一次a就很开心 可以当作kruskal模板题(orz --------------------------------------------------------------------- ...

  2. jmeter循环读取数据库中的数据

    1,添加一个jdbc请求 2,添加一个循环控制器,循环的次数为sql返回的记录数${var_#} 3,添加一个计数器(用来做变量拼接) 4,拼接变量,往目标接口发请求 最后脚本的构造如下:

  3. CSS3实现魔方动画

    本文将借助css3实现魔方动画效果,设计思路如下: HTML方面采用六个div容器形成六个立方面: CSS方面采用transform-style: preserve-3d;形成三维场景:transfo ...

  4. 工具 - 正则Cheat sheet

  5. L298N模块的使用(文末有惊喜)

    这个模块有两个供电口,标示着“12V输入”的是功率驱动电源输入,供电范围可以是7-46V, 一般12V供电就能满足我们大部分的DIY需求.标示着“5V输出可不接”的是逻辑供电, 当我们将“板载5V输出 ...

  6. ModBus的小于3.5S间隔的理解

    modbus协议中规定:至少3.5个字符传输时间的停顿间隔时间标志了消息的结束. 我的理解如下:约定参数:9600bps,8数据位,无奇偶校验,1起始位,1停止位. 9600bps代表在9600的波特 ...

  7. 使用命令将单个java文件打包为jar

    思路:先将java文件编译为class文件,然后再打包为jar 参考博文:https://www.cnblogs.com/sxdcgaq8080/p/8126770.html http://www.m ...

  8. 常用SQL语句大全

    一些常用SQL语句大全   一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql se ...

  9. 洛谷P1140 相似基因(线性DP)

    题目背景 大家都知道,基因可以看作一个碱基对序列.它包含了444种核苷酸,简记作A,C,G,TA,C,G,TA,C,G,T.生物学家正致力于寻找人类基因的功能,以利用于诊断疾病和发明药物. 在一个人类 ...

  10. JSP页面输入框赋值换行显示问题

    <input type="hidden" id="${command.yhzlId}" value="${command.yhzx },${co ...