hdu 1525 Euclid's Game 博弈

Euclid's Game

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


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
 题意: 给你两个数 每次大的数可以减掉小的数的整数倍 知道一个人面临其中一个数为0 的情况那么则为输。。
思路: 比赛的时候一直想枚举某一个状态的后继 如果他的后继中有一个为输的状态 那么他一定为赢的状态 如果一个状态的后继全部是赢的状态 那么他一定是输的状态 ,但是对比较大的数 那么枚举就会很困难。。
在这里我们注意到 两个数 max 和 min 能转移到的状态 ,
如果max%min ==0 那么一定为赢的状态
如果 min ==0 那么一定为输的状态
然后对于max/min>=2 的状态 他一定一定一定会转移到 min max%min 的状态 因为min max%min 的状态是可以确定为赢还是输的状态 而对于先手就可以决定是将 min max%min 状态留给自己还是对手 。
对于max/min>=1 且小于2的情况那么就只有一种转移情况了 就只能转移到 max-min min 的状态。。
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>

using namespace std;

int maxx,minn;

int main()
{
    int t1,t2;
    while(cin>>t1>>t2)
    {
        if(t1==0&&t2==0) break;
        maxx=max(t1,t2);
        minn=min(t1,t2);
        int cnt=1;
        while(1)
        {
            if(minn==0||maxx%minn==0||maxx/minn>=2) break;
            cnt++;
            //printf("%d %d\n",minn,maxx);
            t1=minn;
            t2=maxx-minn;
            maxx=max(t1,t2);
            minn=min(t1,t2);
        }

        if(cnt%2) printf("Stan wins\n");
        else printf("Ollie wins\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
项目:使用AngularJs编写的简单 益智游戏(附源代码)  这是一个简单的 javascript 项目。这是一个拼图游戏,也包含一个填字游戏。这个游戏玩起来很棒。有两个不同的版本可以玩这个游戏。你也可以玩填字游戏。 关于游戏 这款游戏的玩法很简单。如上所述,它包含拼图和填字游戏。您可以通过移动图像来玩滑动拼图。您还可以选择要在滑动面板中拥有的列数和网格数。 另一个是填字游戏。在这里你只需要找到浏览器左侧提到的那些单词。 要运行此游戏,您需要在系统上安装浏览器。下载并在代码编辑器中打开此项目。然后有一个 index.html 文件可供您修改。在命令提示符中运行该文件,或者您可以直接运行索引文件。使用 Google Chrome 或 FireFox 可获得更好的用户体验。此外,这是一款多人游戏,双方玩家都是人类。 这个游戏包含很多 JavaScript 验证。这个游戏很有趣,如果你能用一点 CSS 修改它,那就更好了。 总的来说,这个项目使用了很多 javascript 和 javascript 库。如果你可以添加一些具有不同颜色选项的级别,那么你一定可以利用其库来提高你的 javascript 技能。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值