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):

  1. 25 7

  2. 11 7

  3. 4 7

  4. 4 3

  5. 1 3

  6. 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

  1. 34 12
  2. 15 24
  3. 0 0

Sample Output

  1. Stan wins
  2. Ollie wins

Source

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

[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. mapreduce性能提升2

    mapreduce性能提升2mapreduce性能提升2mapreduce性能提升2

  2. Leetcode: Encode String with Shortest Length && G面经

    Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...

  3. 搭建git for windows服务器

    文档出处 :http://blog.csdn.net/code_style/article/details/38764203 http://blog.csdn.net/aaron_luchen/art ...

  4. [原创]Android Lollipop (5.0) 原生代码 Settings 首页加载逻辑分析

    主入口为com.android.settings.Settings. 这只是一个wrapper的类, 它继承于 SettingsActivity类,并且声明了一堆公有的继承于SettingsActiv ...

  5. iOS简单动画

    知识架构 CALayer 图层类 CABasicAnimation 基础动画 CAKeyFrameAnimation 帧动画 CATransition 转场动画 CAAnimationGroup 动画 ...

  6. Apache部署django项目

    在此之前,我们一直使用django的manage.py 的runserver 命令来运行django应用,但这只是我们的开发环境,当项目真正部署上线的时候这做就不可行了,必须将我们的项目部署到特定的w ...

  7. Upnp资料整理

    系统,软件和路由器都要打开upnp功能. windows7下,分别启动 function discovery resources publication; Upnp device host; SSDp ...

  8. Connect to Database Using Custom params链接数据库配置参数说明

    使用RF的关键字Connect to Database Using Custom params链接数据库,对应的参数说明: a)     第一个参数我使用的是cx_Oracle,就写这个 b)     ...

  9. JS 鼠标滚轮事件(mousewheel/DOMMouseScroll)

    onmousewheel (FireFox不支持此事件) // IE/Opera/Chrome/Safari document.body.onmousewheel = function(event) ...

  10. sql获取时间

    SELECT CONVERT(varchar(10), getdate(), 120)--当前年月日,Example:2013-11-19 SELECT CONVERT(varchar(10), ge ...