hdu 1525 Euclid's Game【 博弈论】
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
如果a % b == 0 先手必胜
如果a >= 2b 那么如果a % b,b是必败态,先手可以把数字改为a % b, b 如果是必胜态 就可以把数字变为a % b + b, b而后手只能操作变成a % b, b 先手必胜
如果a < 2b 就一直减 直到出现必胜态
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<limits>
#include<stack>
#include<queue>
#include<cmath>
#define inf 1000005
using namespace std;
int a, b;
int main()
{
while(scanf("%d%d",&a,&b) != EOF && (a || b)){
if(a < b)
swap(a,b);
if(!(a % b) || a >= 2 * b){
printf("Stan wins\n");
}
else{
int k = 0;
while(a < 2 * b && a % b){
a -= b;
if(a < b){
swap(a,b);
}
++k;
}
if(k % 2){
printf("Ollie wins\n");
}
else{
printf("Stan wins\n");
}
}
}
return 0;
}
hdu 1525 Euclid's Game【 博弈论】的更多相关文章
- hdu 1525 Euclid's Game 博弈论
思路:两个数a和b,总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况. 对于a/b==1这种局面, ...
- HDU 1525 Euclid's Game 博弈
Euclid's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1525 Euclid's Game (博弈)
Euclid's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1525 Euclid's Game
题目大意: 题目给出了两个正数a.b 每次操作,大的数减掉小的数的整数倍.一个数变为0 的时候结束. 谁先先把其中一个数减为0的获胜.问谁可以赢.Stan是先手. 题目思路: 无论a,b的值为多少,局 ...
- HDU 1525 Euclid Game
题目大意: 给定2个数a , b,假定b>=a总是从b中取走一个a的整数倍,也就是让 b-k*a(k*a<=b) 每人执行一步这个操作,最后得到0的人胜利结束游戏 (0,a)是一个终止态P ...
- HDU.2516 取石子游戏 (博弈论 斐波那契博弈)
HDU.2516 取石子游戏 (博弈论 斐波那契博弈) 题意分析 简单的斐波那契博弈 博弈论快速入门 代码总览 #include <bits/stdc++.h> #define nmax ...
- HDU.2147 kiki's game (博弈论 PN分析)
HDU.2147 kiki's game (博弈论 PN分析) 题意分析 简单的PN分析 博弈论快速入门 代码总览 #include <bits/stdc++.h> using names ...
- HDU 1525 类Bash博弈
给两数a,b,大的数b = b - a*k,a*k为不大于b的数,重复过程,直到一个数为0时,此时当前操作人胜. 可以发现如果每次b=b%a,那么GCD的步数决定了先手后手谁胜,而每次GCD的一步过程 ...
- A - 无聊的游戏 HDU - 1525(博弈)
A - 无聊的游戏 HDU - 1525 疫情当下,有两个很无聊的人,小A和小B,准备玩一个游戏,玩法是这样的,从两个自然数开始比赛.第一个玩家小A从两个数字中的较大者减去两个数字中较小者的任何正倍数 ...
随机推荐
- css段落首字母下沉
摘要: 段落首字母放大是指放大段落开头的字母或者汉字,主要使用了css的first-letter伪类选择器. 单行放大: 在第一行内放大,效果如下: <!DOCTYPE html> < ...
- Java从控制台接受输入字符
创建一个类,在该类的主方法中创建Scanner扫描起来封装System类的in输入流,然后提示用户输入身份证号码,并输入身份证号码的位数. 代码如下: import java.util.Scanner ...
- TCP拥塞控制算法纵横谈-Illinois和YeAH
周五晚上.终于下了雨.所以也终于能够乱七八糟多写点松散的东西了... 方法论问题. 这个题目太大以至于内容和题目的关联看起来有失偏颇.只是也无所谓,既然被人以为"没有方法论"而歧视 ...
- spring定时任务详解(@Scheduled注解)多线程讲解
(一)在xml里加入task的命名空间 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns ...
- 2. Oracle体系结构
一. Oracle体系结构图 体系结构图如下: 体系结构图看似简单:其中很有玄机.它对Oracle来讲:相当于武功中的心法.配合体系结构来学Oracle:能起到事半功倍的效果.我们平时遇到Oracle ...
- iOS开发-- 使用VVDocumenter-Xcode添加代码注释
在开发Java代码过程中,我们只需在Eclipse中敲/**即可生成字段.方法对应的文档,简单便捷. 在Xcode如果想添加文档注释,需要花费很多时间,有没有简单.快速的方法搞定这一切? 在网上搜索了 ...
- 架设FTP Server-Windows Server 2012
架设FTP Server-Windows Server 2012 https://jingyan.baidu.com/article/03b2f78c75b9b65ea237ae84.html 在 ...
- bootstrap 中这段代码 使bundles 失败
_:-ms-fullscreen, :root input[type="date"], _:-ms-fullscreen, :root input[type="time& ...
- Microsoft Security Essentials
https://support.microsoft.com/zh-cn/help/18900/consumer-antivirus-software-providers-for-windows 适 ...
- LeetCode 20 Valid Parentheses (括号匹配问题)
题目链接 https://leetcode.com/problems/valid-parentheses/?tab=Description Problem: 括号匹配问题. 使用栈,先进后出! ...