Los solution to a problem Valley P1290 [Euclid Games

This problem did not need so much trouble, you only need to look at the reasoning:

Suppose we have two numbers \ (the X-, the y-\) , first \ (x \) is set to a large value, \ (the y-\) is set to a smaller value. Now divided into three cases:

\ (1 \) . If the number is a multiple of two relations, one winning operation.

\ (2 \) . If the two quotient \ (> 1 \) , it is still operating the winning party.

\(why?\)

Take for example \ (25,7 \) is. In this case the operation side has three options: \ (18 \) \ (7 \) , \ (11 \) \ (7 \) , \ (4 \) \ (7 \)

If he chose \ (18 \) \ (7 \) , then the latter will face the \ (11 \) \ (7 \) or \ (4 \) \ (7 \) ; and if he does not choose \ (18 \) \ (7 \) , then his face or \ (11 \) \ (7 \) or \ (4 \) \ (7 \) .

At this point you will find that \ (11 \) \ (7 \) and \ (4 \) \ (7 \) is a must win, but both smart enough, so who has the right to choose who will be able win! That he can not choose \ (18 \) \ (7 \) !

Again give a chestnut: \ (31 \) \ (6 \)

Then you will find, just get party only option \ (7 \) \ (6 \) or \ (1 \) \ (6 \) to ensure control of his hands, but apparently \ (1 \) \ (6 \) is not enough, you can only choose \ (7 \) \ (6 \) . Thus \ (7 \) \ (6 \) \ (- \) \ (6 \) \ (1 \) \ (- \) \ (6 \) \ (0 \) , the result is the upper hand to win!

Then you should know: who has the right to choose (select two or more) who will win!

\ (3 \) . Quotient is \ (1 \) , continued

For chestnuts, such as \ (6 \) \ (4 \) , then the upper hand no choice, it will only continue to argue, as \ (2 \) \ (4 \) .

\(Code:\)

#include<bits/stdc++.h>
using namespace std;
bool check(int x,int y){
    for(int i=1;;i++){
        int ma=max(x,y);
        int mi=min(x,y);
        x=ma,y=mi;
        //x为两数较大值,y为两数较小值 
        if(x%y==0){
            return i%2;//若两数为倍数关系,操作的一方赢
        }else if(x/y>1){
            return i%2;//若两数商>1,那么还是操作一方赢
        }else{
            x-=y;//否则说明商为1,那就继续 
        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x,y;
        cin>>x>>y;
        if(check(x,y))cout<<"Stan wins"<<endl;
        else cout<<"Ollie wins"<<endl;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/Agonim/p/12080772.html