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. 18.有一个网页地址, 比如PHP开发资源网主页: http://www.phpres.com/index.html,如何得到它的内容?

    方法1(对于PHP5及更高版本): $readcontents = fopen("http://www.phpres.com/index.html", "rb" ...

  2. jsp+servlet 中文乱码问题

    一. 由于doget和dopost的处理方式不同,在做servlet的时候遇到这样一个问题:用doPost获得的参数只要加上“request.setCharacterEncoding("ut ...

  3. 最新IP地址数据库 二分逼近&二分查找 高效解析800万大数据之区域分布

    最新IP地址数据库  来自 qqzeng.com 利用二分逼近法(bisection method) ,每秒300多万, 比较高效! 原来的顺序查找算法 效率比较低 readonly string i ...

  4. C# 使用BackgroundWorker例子及注意点

    该例子为使用BackgroundWorker在TextBox文本中产生一个10000以内并且能被5整除的数(1秒产生一个) 操作界面可以启动线程,也可以停止线程,界面设计如图: 先贴代码,有注释的地方 ...

  5. Android 短信广播接收相关问题

    本人是Android新手,最近做了一个关于监听手机短信功能的应用,我在网上看资料了解到广播分为有序广播和无序广播,有序广播:无序广播又称普通广播,其中的利弊我也一时没搞清楚,我用的是有序广播实现的,具 ...

  6. 手机APP功能测试经验分享2016.06.06

    1.登录时,Android和IOS同样的操作,提示信息不一致: 2.注册等页面切换成横屏容易不兼容.把内存卡去掉,再发送图片.音频.视频容易出错. 3.Android和IOS同样的功能,同样的原型图, ...

  7. Android Bootloader LittleKernel的两篇文章 【转】

    转自:http://blog.csdn.net/loongembedded/article/details/41747523 2014-12-05 14:37 3599人阅读 评论(2) 收藏 举报 ...

  8. ftp发送文件

    #!/bin/bash #author:luyongjin IP=220.250.65.22 USERNAME='ftp_hangye20' PASSWORD='oUo2JD7oK#u-epw' #D ...

  9. jsp中button与submit的用法

    button:可以对返回的数据进行格式化,反应到页面上,可以用form表单序列化提交也可以不用form表单提交 <form id="addForm"> <inpu ...

  10. MYSQL中存储过程的创建,调用及语法

    MySQL 存储过程是从 MySQL 5.0 开始增加的新功能.存储过程的优点有一箩筐.不过最主要的还是执行效率和SQL 代码封装.特别是 SQL 代码封装功能,如果没有存储过程,在外部程序访问数据库 ...