Euclid's Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9033   Accepted: 3695

Description

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.

Input

The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.

Output

For 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

Source

 
 
老师的惊天模拟赛#1
 
TAT我天真的以为我会这道题了
很容易想到对于两堆数字,只有两种决策:拿一个或者拿多个
对于a>b且a<2*b的情况,只能拿一种,因此可以确定先后手
当可以拿多次时,要么全取走能取走的,要么再留下一次能取的量
所以对两个数做一次gcd
每次取模前判断可以取几次数字,得到一个序列仅包含1和2
(我只想到这里)
(话说讲博弈论的时候我好像睡着了怪不得)
对于连续的1,可以立刻判断结尾先手还是后手
但对于一个2,只要有一方遇到了2,他就可以操纵局势
即在2结束后,他一定可以让自己位于序列结尾或下一个2
那么在gcd的时候,只需记录出现第一个2的时候是先手还是后手即可
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define LL long long
int main(){
int tmp,n,m,pl;
while(scanf("%d %d",&n,&m)!=EOF&&(n&&m)){
pl=;
while(n&&m){
if(m<n){tmp=m;m=n;n=tmp;}
if((n<<)>&&m>=(n<<))break;
m=m%n;
if(!m)break;
pl^=;
}
if(!pl)puts("Stan wins");
else puts("Ollie wins");
}
return ;
}

[poj2348]Euclid's Game(博弈论+gcd)的更多相关文章

  1. 【博弈论】poj2348 Euclid's Game

    假设当前b>a. 一.b%a==0 必胜 二.b<2*a,当前我们没有选择的余地,若下一步是必胜(最终能到情况一),则当前必败:反之,当前必胜. 三.b>2*a,假设x是使得b-ax ...

  2. POJ 2348 Euclid's Game 博弈论

    http://poj.org/problem?id=2348 顺便说,必应翻译真的好用,比谷歌翻译好用100倍. 很难判断这道题的具体博弈类型. 有两种写法,一种是找规律,一种是推理得到关系后循环(或 ...

  3. hdu 1525 Euclid's Game 博弈论

    思路:两个数a和b,总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况. 对于a/b==1这种局面, ...

  4. [POJ2348]Euclid's Game

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8313   Accepted: 3374 Description Two p ...

  5. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  6. Design and Analysis of Algorithms_Introduction

    I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...

  7. C#读取图片Exif信息

    Exif是可交换图像文件的缩写,是专门为数码相机的照片设定的,可以记录数码照片的属性和拍摄数据 ////调用 //string strFile="fffff.jpg";//文件名 ...

  8. C++基础学习教程(五)

    这一讲我们集中解说类和他的一些特性.首先我们从自己定义一个有理数类来開始. 在C语言中有一个keyword: struct ,用来创建一个结构体类型.可是在C++中这个关键的含义就不只如此了,以下我们 ...

  9. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

随机推荐

  1. WebForm 常用控件

    一.简单控件 1.Label(作用:显示文字) Web中: <asp:Label ID="Label1" runat="server" Text=&quo ...

  2. 解读ContentResolver和ContentProvider

    转自:http://cthhqu.blog.51cto.com/7598297/1281217 1. ContentProvider的概述 ContentProvider: (Official Def ...

  3. js隐式转换

    JavaScript的数据类型分为六种,分别为null,undefined,boolean,string,number,object.object是引用类型,其它的五种是基本类型或者是原始类型.我们可 ...

  4. 常用的Linux命令

    1.如何创建一个目录?mkdir DirectoryName 2.如何进入服务器根目录?ls / 3.如何查看日历?cal 4.如何修改密码?passwd 5.如何查看当前用户信息?whoami 6. ...

  5. Ext.Net_1 配置ext.net所需的环境

    一.配置ext.net有两种方法,一是通过自动配置,即:工具--->Nuget包管理器--->管理解决方案的Nuget程序包--->搜索EXT.NET--->安装,安装完后,环 ...

  6. mysql时间格式化,按时间段查询的MySQL语句

    描述:有一个会员表,有个birthday字段,值为'YYYY-MM-DD'格式,现在要查询一个时间段内过生日的会员,比如'06-03'到'07-08'这个时间段内所有过生日的会员. SQL语句: Se ...

  7. jsonp 使用总结

    首先:jsonp是json用来跨域的一个东西. 原理是通过script标签的跨域特性来绕过同源策略. 发送端: $.ajax({ type : "post", url : &quo ...

  8. 使用bat/vbs/ahk对Windows下进行自动化操作

    回想90年代,我们在DOS下使用各种命令链对操作进行简化和自动化,如DOS 5.0添加的DosKey,利用管道和重定向对多组命令进行链式操作.后来使用了Ubuntu和其它Linux发型版后,bash下 ...

  9. PHP 微信分享

    share.php <?php //公众号设置一下 JS接口安全域名,不要http,www的一级域名,比如http://www.baidu.com域名下的某个路径要分享,js安全域名中只需填上 ...

  10. [linux系统]--spawn 用法

    spawn与except组合可达到远程登录设备执行命令的作用 下面是登录设备的一段代码 #!/usr/bin/expect -f user=root host=1.1.1.1 password=roo ...