zoukankan      html  css  js  c++  java
  • POJ 2348 Euclid Game (模拟题)

    Euclid's Game
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 7942   Accepted: 3227

    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

    可以参考:《基础训练题解》哈尔滨出版社 俞经善...等编
    题意讲解:两个人Ollie和Stan玩一个游戏,每次输入两个非负数。 Stan为先手,Ollie为后手。
    每次从大数中减去小数的任意倍数,将其减完后的结果赋值给被减的大数。Ollie刚才的游戏规则,
    然后进行循环。直到小数不能再大数中拿到一个非0的数为止。最后一个拿到数的玩家为赢家。

    算法讲解:大数除以小数,当值大于1时,正在进行此次游戏的玩家为赢家。否则要继续游戏。
    当游戏进行了偶数次的时候,就是Stan赢,否则就是Ollie赢了。
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    #include <stdio.h>
    #include <iostream>
    #include <string>
    #include <algorithm>
    
    using namespace std;
    
    int main()
    {
    	int x, y;
    	while(scanf("%d %d", &x, &y)!=EOF)
    	{
    		if(x==0 && y==0) break;
    
    		int dd;
    		int cnt=0; //记录游戏进行次数
    		int n=x; int m=y;
    		while(n!=0 && m!=0 )
    		{
    			if(m>n){
    				cnt++;
    				dd = m/n;
    				m=m%n; //大数被赋值成那个差值
    				if(dd >= 2) break;
    			}
    			else{
    				cnt++;
    				dd=n/m;
    				n=n%m;
    				if(dd>=2 ) break;
    			}
    		}
    		if(cnt%2==1) printf("Stan wins
    ");
    		else
    			printf("Ollie wins
    ");
    	}
    	return 0;
    }
    
    
    
    


  • 相关阅读:
    zabbix:以主动模式添加一台受监控主机 (zabbix5.0)
    linux(centos8):用grep命令查找文件内容
    zabbix安装中文语言包及中文乱码的解决(zabbix5.0)
    性能测试常用术语
    Java 读写Properties配置文件
    携程Apollo配置中心架构深度剖析
    jmeter 使用csv文件 注意项
    CnPlugin_1.5.1 解决win10 pl/sql 输入法卡顿 兼容性问题
    jmeter(psot) 表单提交 注意项
    全新OCR3500数据
  • 原文地址:https://www.cnblogs.com/yspworld/p/4337376.html
Copyright © 2011-2022 走看看