POJ 2348 Euclid Game (simulated problem)

Source: Internet
Author: User

Euclid ' s Game
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7942 Accepted: 3227

Description

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
6 U
4 3
1 3
1 0

An Stan wins.

Input

The input consists of a number of lines. Each line contains the positive integers giving the starting of the game. Stan always starts.

Output

For each line of input, the output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly. The last line of input contains, zeroes and should not be processed.

Sample Input

34 1215 240 0

Sample Output

stan Winsollie wins 

can be consulted: "Basic Training" Harbin Press Shanshan ...
Test instructions Explanation: Two people Ollie and Stan play a game and enter two non-negative numbers at a time. Stan is the initiator, Ollie for the other.
each time you subtract any multiple of a decimal from a large number, the result of which it is subtracted is assigned to the larger number that is subtracted. ollie just the rules of the game,
and then loop. Until a decimal number cannot be reached in a number other than 0. The last player to get a number wins. The

algorithm explains: A large number divided by a decimal, the value is greater than 1 o'clock, the player who is playing this game is the winner. Otherwise you will continue the game.
When the game is done even several times, Stan wins, or Ollie wins.
#include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #include < stdio.h> #include <iostream> #include <string> #include <algorithm>using namespace Std;int main () { int x, Y;while (scanf ("%d%d", &x, &y)!=eof) {if (x==0 && y==0) break;int dd;int cnt=0;//record number of game times int n=x; in T M=y;while (n!=0 && m!=0) {if (m>n) {cnt++;dd = m/n;m=m%n;//large number is assigned to that difference if (dd >= 2) break;} else{cnt++;dd =n/m;n=n%m;if (dd>=2) break;}} if (cnt%2==1) printf ("Stan wins\n"); elseprintf ("Ollie wins\n");} return 0;}



POJ 2348 Euclid Game (simulated problem)

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.