hdu 1525

Euclid‘s Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2193    Accepted Submission(s): 981

Problem 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

University of Waterloo Local Contest 2002.09.28

a>b

其中 先手必胜状态,有 b==0 ,a/b>=2,a%b==0

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;
int a,b;
int main()
{
      while(scanf("%d%d",&a,&b)!=EOF)
      {
            if(a==0&&b==0)
                  break;
            if(a<b) swap(a,b);
            bool flag=true;
            while(1)
            {
                  if(b==0||a%b==0||a/b>=2)
                        break;
                  int t=b;
                  b=a-b;
                  a=t;
                  flag=!flag;
            }
            if(flag)
            {
                  printf("Stan wins\n");
            }
            else
                  printf("Ollie wins\n");
      }
      return 0;
}

  

时间: 2024-11-03 20:09:16

hdu 1525的相关文章

hdu 1525 Euclid&#39;s Game 博弈

Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2219    Accepted Submission(s): 1000 Problem Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan

hdu 1525 Euclid&#39;s Game

Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2074    Accepted Submission(s): 924 Problem Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan,

HDU 1525 博弈

Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1880    Accepted Submission(s): 825 Problem Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan,

HDU 1525 (博弈) Euclid&#39;s Game

感觉这道题用PN大法好像不顶用了,可耻地看了题解. 考虑一下简单的必胜状态,某一个数是另一个数的倍数的时候是必胜状态. 从这个角度考虑一下:游戏进行了奇数步还是偶数步决定了哪一方赢. 如果b > 2a,那么这一方就有权利改变游戏步数的奇偶性,从而到达对自己有利的状态,所以这是一个必胜状态. 如果a < b < 2a,那么下一步只能到达(b-a, a)状态,一直模拟就行. 1 #include <cstdio> 2 #include <algorithm> 3 us

[简单博弈] hdu 1525 Euclid&#39;s Game

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1525 Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1832    Accepted Submission(s): 808 Problem Description Two players, Stan and

hdu 1525 找规律博弈 (根据每一步的必然性以及可选择性决策)

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1525 题意: 给出两个数,a和b,将大的数中,减去若干b的倍数,最终有一个数为0的话就胜了. 分析:  两个数a和b, 不妨设(a > b),总会出现的一个局面是b,a%b,这是必然的,如果a>=b&&a<2*b,那么只有一种情况,直接到b,a%b.否则有多种情况. a / b == 1   即a Ε [b , 2b)  , 下一步 只能到达   (b , a  - b) a

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201