hdu 1525 Euclid's Game

给出  a,b , 每个人 可以 将 大的数 可以减去 小的数的倍数,但不能变成负的, 谁先出现 x ,0 的状态 谁赢。


假设 当前可以选择的倍数k 是大于2 的, 那么这个状态就是必胜的。  a,b 转化成  b ,a%b 时, 若b, a%b 是必胜, 只要转化成 a%b+b , b 这个状态。

若 b,a%b 必败, 则 直接转化成 b ,a%b 。

那么 决定先手胜负的就是, 开始的 1 的个数, 因为 当 a, b 只有一种选择时 ,状态只有一种转移,谁先转化到偶数 或者谁先到最有一步,谁赢。


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <cstring>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cstdlib>
#include <ctime>
#include <assert.h>
#include <queue>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALLL(x) x.begin(),x.end()
#define SORT(x) sort(ALLL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILLL(x,c) memset(x,c,sizeof(x))
using namespace std;
 
const double EPS = 1e-8;

#define LL long long 
#define pb push_back
int a,b;
;
int tot;
int num[100];
int gcd(int a,int b){
    if(b==0)return a;
    if(a>=b){
       int t = a/b;
       tot ++ ;
       num[tot] =t;
    }
    
    return gcd(b,a%b);
}
int main(){
    while(scanf("%d%d",&a,&b),a|b){
        
        tot= 0 ;
        gcd(a,b);
        int ans= 0;
        int st =0;
        for(int i=1;i<tot;i++){
            //if(num[i]>1)ans ++;
            if(!st && num[i]>1){
                st = i;
                break;
            }else if(!st){
                ans ++;
            }
        }
        
        if(ans&1){
            puts("Ollie wins");
        }else{
            puts("Stan wins");
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值