洛谷P1290 欧几里德的游戏

题目:https://www.luogu.org/problemnew/show/P1290

只要出现n>=2*m,就可以每次把较大的数控制在较小的数的一倍与二倍之间,则控制了对方的走法;

每次取后两个数大小交换,这时可能出现整除,而上述方法可以保证每次可能出现整除时都轮到自己,所以必胜。

代码如下:

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll c,n,m;
int main()
{
    scanf("%lld",&c);
    while(c--)
    {
        scanf("%lld%lld",&n,&m);
        if(n<m)swap(n,m);
        if(n%m==0||n>2*m)
        {
            printf("Stan wins
");
            continue;
        }
        bool t=0;
        while(1)
        {
            n-=m;
            if(n<m)swap(n,m);
            if(n>2*m||n%m==0)
            {
                if(!t)printf("Ollie wins
");
                else printf("Stan wins
");
                break;
            }
            t=!t;
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Zinn/p/9073428.html