hdu 1525 Euclid's Game

来源:互联网 发布:语文句子成分划分软件 编辑:程序博客网 时间:2024/06/16 13:50

给出  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_backint 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;}


原创粉丝点击