Zoj 1913 Euclid's game Game Theory

Source: Internet
Author: User
Description

Tom and Tom are playing the Euclidean game. They start from two natural numbers. The first player, James, is able to subtract the largest positive integer multiple of the two numbers as much as possible, as long as the difference is non-negative. Then, the second player was lucky enough to perform the same operation on the two numbers, followed by James. In this way, the game is played in turn until a player returns a large number minus a multiple of a decimal number and returns 0. At this time, the game ends and the player is the winner.

Input Format

The input contains multiple groups of test data. Each group has two positive integers, indicating the first two numbers of the game.
When two zeros are input, the input ends.

Output

For each group of input and output winners, we think they are both top players and each game has made the best choice.
For the specific output format, see the output sample.

Sample Input

34 12
15 24
0 0

Sample output

Xiaoming wins
Xiaohong wins


Ideas:

There are three scenarios:

M is a large number. N is a decimal number.

When M % N = 0: whoever wins

When M/N is equal to 1, there is only one method (m, n)-> (n, m % N)

Who wins when M/N> = 2: Because when (n, m % N) if it is a mandatory state, the attacker can take it as (M % N + n, n), then the loser State is transferred to another person. If (M % N + n, n) is a mandatory defeat

The accessors can be (n, m % N), which is also called the first-hand advantage.


Code:

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int main(){    int a,b,tt,t;    while(scanf("%d%d",&a,&b)==2&&a+b)    {        tt=1;        while(1)        {          if(b>a)          {              t=a;              a=b;              b=t;          }          if(a%b==0||a/b>=2)                 break;                   tt=!tt;             a=a%b;        }        if(tt==1)            printf("xiaoming wins\n");        else            printf("xiaohong wins\n");    }    return 0;}


Zoj 1913 Euclid's game Game Theory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.