Euclid's Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7418   Accepted: 3022

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

 
分两种情况 b - a < a b - a > a
第一种情况别无选择,第二种情况必胜,由此可得答案
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int a, b; bool check() {
bool flag = ;
for(;;) {
if(a > b) swap(a,b);
if(b % a == ) break;
if(b - a > a) break;
b -= a;
flag = !flag;
} return flag;
}
int main()
{
while(~scanf("%d%d",&a, &b) && (a + b)) {
if(check()) {
printf("Stan wins\n");
} else {
printf("Ollie wins\n");
}
}
//cout << "Hello world!" << endl;
return ;
}

poj 2348的更多相关文章

  1. poj 2348 Euclid's Game 题解

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9023   Accepted: 3691 Des ...

  2. POJ 2348 Euclid's Game(辗转相除博弈+自由度分析)

    题目链接:http://poj.org/problem?id=2348 题目大意:给你两个数a,b,Stan和Ollie轮流操作,每次可以将较大的数减去较小的数的整数倍,相减后结果不能小于0,谁先将其 ...

  3. POJ 2348 Euclid's Game 博弈论

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

  4. POJ 2348 Euclid's Game(博弈论)

    [题目链接] http://poj.org/problem?id=2348 [题目大意] 给出两个数,两个参赛者轮流用一个数减去另一个数的倍数,当一个数为0的时候游戏获胜, 求先手是否必胜 [题解] ...

  5. POJ 2348 Euclid's Game【博弈】

    题目链接: http://poj.org/problem?id=2348 题意: 给定两个数,两个人每次从较大数中减去较小数的倍数,谁先得到0谁获胜,为谁赢? 分析: 令一种可能出现的整数对为(a,b ...

  6. POJ 2348 Euclid's Game(简单博弈)

    这道题没说a b最大多少,所以要声明为long long型,不然会WA! 道理很简单,(默认a>=b)a和b只有以下三种关系: 1.a%b==0 :这种关系下,可能是a/b为整数,也可能是a和b ...

  7. 4.1.3 Euclid's Game (POJ 2348)

    Problem description: 以辗转相除法为基础,给定两个整数a和b,Stan和Ollie轮流从较大的数字中减去较小数字的倍数(整倍数),并且相减后的结果不能为零.Stan先手,在自己的回 ...

  8. POJ 2348 Euclid's Game(博弈)题解

    题意:有a,b两个数字,两人轮流操作,每次可以选择两个之中较小的数字,然后另一个数字减去选择数字的任意倍数(不能减到负数),直到其中一个为0,不能操作为败 思路:这题用博弈NP思想,必败点和必胜点之间 ...

  9. poj 2348 Euclid's Game

    题目: 给两个整数a和b,两个人先后用较大的数减去较小数的整数倍,并且保证相减后为非负数.先把一个数变为0的人获胜. 分析: 很显然,当大数是小数的整数倍时为必胜态. 从这道题学会一个叫做自由度的东西 ...

随机推荐

  1. 使用checked关键字处理“溢出”错误

    在进行算术运算时,可以使用checked关键字有效处理溢出错误,使用checked关键字可能对程序的性能会有一点点的影响,这是一种以牺牲性能换取健康的做法. private void button1_ ...

  2. GoAhead 嵌入式web

    https://embedthis.com/goahead/ 入手了一个360  4g  wifi :使用jquery  .goahead Goahead webserver编辑 GoAhead We ...

  3. Swift function how to return nil

    这两天在学习Stanford出品的iOS7的课程,这个课程去年也看过,但是看到第3课就不行了,满篇的OC,把人都搞晕了.这段时间因为要写个iOS的App,正好赶上了Swift问世,所以趁着这股劲继续学 ...

  4. Linux系统木马后门查杀方法详解

    木马和后门的查杀是系统管理员一项长期需要坚持的工作,切不可掉以轻心.以下从几个方面在说明Linux系统环境安排配置防范和木马后门查杀的方法: 一.Web Server(以Nginx为例) 1.为防止跨 ...

  5. [转]Valgrind简单用法

    [转]Valgrind简单用法 http://www.cnblogs.com/sunyubo/archive/2010/05/05/2282170.html Valgrind的主要作者Julian S ...

  6. 不同系统间传输float型数据

    #include <stdio.h> #include <string.h> int main(void) { union result {          float d; ...

  7. [SSH服务]——SSH详解、常用的远程连接工具

    在总结ssh原理前,我先做了一个ssh过程的实验 首先我搭建了这样一个实验环境: (1) SSH Server:10.0.10.198 (2) SSH Client:10.0.10.158 在Serv ...

  8. 20145120 《Java程序设计》实验二实验报告

    20145120 <Java程序设计>实验二实验报告 实验名称:Java面向对象程序设计 实验目的与要求: 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握U ...

  9. 面向对象版js分页

    基于前一个js分页,我将代码改成一个面向对象版的js分页,代码如下 http://peng666.github.io/blogs/pageobj <!DOCTYPE html> <h ...

  10. appium-UI automator viewer 无[ resource-id ]项

    问题:UI automator viewer 无[ resource-id ]项,如下图 解决办法: 手机android  版本太低导致(本人4.2.2),在android4.3机子上运行正常