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. ios开源

    a http://code.cocoachina.com b http://code4app.com c http://www.oschina.net/ios/codingList/ d github ...

  2. JAVA(5)之关于main函数的默认放置位置

    Eclipse默认主程序入口 Public class 的main函数 package com.study; public class Test { public static void main(S ...

  3. gRPC Learning Notes

    简介 更多内容参考:https://www.grpc.io/docs/guides/ gRPC 是一个高性能.开源和通用的 RPC 框架,面向移动和 HTTP/2 设计.目前提供 C.Java 和 G ...

  4. Ubuntu mysql 在线安装

    $ sudo apt install mysql-server

  5. Java方法升级

    1. 方法格式 package cn.itcast.day04.demo02; /* 方法其实就是若干语句的功能集合. 方法好比是一个工厂. 蒙牛工厂 原料:奶牛.饲料.水 产出物:奶制品 钢铁工厂 ...

  6. 【C语言】判断某一正整数是否为完数

    什么是完数? 如果一个数等于它的因子之和,则称该数为“完数”(或“完全数”). 例如,6的因子为1.2.3,而 6=1+2+3,因此6是“完数”. 程序框图:m  问题分析 根据完数的定义,解决本题的 ...

  7. 【MySQL】多表查询

    " 目录 多表链接查询 笛卡尔积 内链接 inner join 外链接之左链接 left join 外链接之右链接 right join 全外链接 符合条件链接查询 子查询 先准备两张表:部 ...

  8. Linux - 查看所有服务状态

    ubuntu: service --status-all 例如可查看ssh, apache2等服务是否开启

  9. python:布尔类型

    bool:有两个值,True 和 False bool 其实是int类型的一个子类,True一般为1,False一般为0 判断前一个是否是后一个的子类:issubclass(A, B) 内建函数boo ...

  10. 连接mysql,oracle的命令 以及导入sql文件

    Oracle 1,sqlplus  username/password 导入: 2,@后面跟着sql文件的路径,回车,导入数据 @D:/test.sql; 导入完毕,输入commit; MySQL: ...