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从两个数字中的较大者减去两个数字中较小者的任何正倍数 ...
随机推荐
- node.js--Less
摘要: 现在已经有许多站点使用Node.js,所以在Node.js上配置Less环境也是很重要的,下面分享下如何在Node上使用Less开发,前提是你电脑上已经安装node. 安装: 只需要执行下面一 ...
- VS2010安装包制作全过程图解
项目的第一个版本出来了,要做个安装包,很久没做过已经有些淡忘了,网上差了差资料,写了一个,总结下,可能还不是很完善,仅作参考. 1.首先在打开 VS2010 >新建>项目 2.创建一 ...
- SaltStack salt-ssh 用法
以下在 master 操作: (1) 我们在安装部署 SaltStack 的时候,需要安装 salt 客户端,还要与 salt 服务端进行认证才能互相通信(2) 如果我们使用 salt-ssh 的方式 ...
- C++程序中调用其他exe可执行文件方法
在编程过程中有个需求,点击某个按钮需要弹出系统的声音控制面板.在网上查了下代码中调用其他exe程序或者打开其他文件的方法. 自己借鉴网上的文章稍微总结下,加深下印象,也给方便自己用. 在代码中调用其他 ...
- pycharm2016.2.3注册码到期, 激活, 破解版
python工具下载: https://pan.baidu.com/s/1kVEDOrl#list/path=%2F 密码:ko1i 注册码有效期是一年,到期后需再次激活 分享破解版 或者重新注册码激 ...
- SQL —— 获取重复某个字段的第一条记录
----------用来双重排序,且获取唯一 go SELECT ROW_NUMBER() OVER (ORDER BY AScore DESC,ATime ASC) AS Rank, * FROM ...
- Hive学习之数据去重
insert overwrite table store select t.p_key,t.sort_word from ( select p_key, sort_word , row_number( ...
- [转]OpenStack Neutron运行机制解析概要
转载自:http://panpei.net.cn/2013/12/04/openstack-neutron-mechanism-introduce/ 自从开学以来,玩OpenStack也已经3个月了, ...
- Android MediaScanner
一.MediaScanner 的使用 1)Intent.ACTION_MEDIA_SCANNER_SCAN_FILE:扫描指定文件 public void scanFileAsync(Context ...
- 【读书笔记】socket描述符选项[SOL_SOCKET]
#include <sys/socket.h> int setsockopt( int socket, int level, int option_name, ...