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;
    }
    
    
    
    


  • 相关阅读:
    03点云文件常用格式转换(pcd,txt,ply,obj,stl)
    04点云数据结构格式
    vs2015 +ZXing/Zbar的环境配置
    01PCL 点云+vs2015在win10下的环境配置
    07点云的滤波与分割
    gitlabCI/CD部署一个java项目
    k8s 为什么需要数据卷
    gitlab Runner 安装与部署
    gitlab ci/cd介绍
    k8s emptyDir临时数据卷
  • 原文地址:https://www.cnblogs.com/yspworld/p/4337376.html
Copyright © 2011-2022 走看看