HDU 1525 Euclid ' s game game theory

Source: Internet
Author: User
Tags printf


Players, Stan and Ollie, play, starting with and natural numbers. Stan, the first player, subtracts any positive multiple of the of the lesser of the numbers from the greater of the RS, provided the resulting number must be nonnegative. Then Ollie, the second player, does the same with the and the resulting numbers, then Stan, etc, alternately, until one Playe R is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players could start with (25,7):

25 7
11 7
4 7
4 3
1 3
1 0

An Stan wins.

Inputthe input consists of a number of lines. Each line contains the positive integers giving the starting of the game. Stan always starts. Outputfor each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play PERFEC tly. The last line of input contains, zeroes and should not be processed.

Sample Input

0 0
Sample Output
Stan wins
Ollie wins

If a% b = = 0 Initiator win

If a >= 2b then if a% b,b is a must, the initiator can change the number to a% B, b if it is a win state can change the number to a% B + B, B and the hand can only operate into a% B, b initiator win

If a < 2b has been reduced until the winning state is present

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream >
#include <limits>
#include <stack>
#include <queue>
#include <cmath>
#define INF 1000005

using namespace std;

int a, B;

int main ()
{
    while (scanf ("%d%d", &a,&b)! = EOF && (A | | b)) {
        if (a < b)
            swap (b);
        if (! ( A% b) | | A >= 2 * b) {
            printf ("Stan wins\n");
        }
        else{
            int k = 0;
            while (A < 2 * b && a% b) {
                a = B;
                if (a < b) {
                    swap (b);
                }
                ++k;
            }
            if (k% 2) {
                printf ("Ollie wins\n");
            }
            else{
                printf ("Stan wins\n");
    }}} return 0;
}


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.