poj2505a Multiplication Game

Source: Internet
Author: User


The easy water person goes, the moon is like frost.






Description Stan and Ollie play the game of multiplication by multiplying a integer p by one of the numbers 2 to 9. Stan always starts with P = 1, does he multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner are who first reaches P >= N.



Input each line of input contains one integer number N.



Output for each line of input output one line either
Stan wins.
Or
Ollie wins.
Assuming that both of them play perfectly.



Sample Input


162
17
34012226


Sample Output


Stan wins.
Ollie wins.
Stan wins.





The main idea: Two people take turns playing the game, Stan Initiator, the number p starting from 1, Stan multiplied by a 2-9 number, and then Ollie multiplied by a 2-9 number, until the person who first took p to P>=n when the man won, and when the turn of someone, someone must multiply 2-9 a number.



Problem Solving Ideas:



Game, to find the law, first we easily get in



[2,9] This interval is Stan winning.



[10,18] This interval, is Ollie win



Then the left side of the next interval must be [18+1,. It's Stan's victory.



The interval should be filled in what number, because 18 is a must defeat, so the turn to Stan start, then he can be multiplied by a 9, that is, 18*9, Stan will win.



We can think of 18 as 9*2, which means that the more Stan wants to approach N,ollie, the more he doesn't want him to reach N



So the next interval is [18+1,9*2*9], in fact, to find a law can also find a law



[9*2*9+1,9*2*9*2],ollie win



[9*2*9*2+1,9*2*9*2*9],stan Winning code:





#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
const int maxn=10000;
using namespace std;
int main (void)
{
    long long num;
    while (~SCANF ("%lld", &num))
    {
        if (num<=9)
        {
            printf ("Stan wins.\n");
            Continue;
        }
        if (num>9&&num<=18)
        {
            printf ("Ollie wins.\n");
            Continue;
        }
        while (num>18)
        {
            num= (num-1)/18+1;
        }
        if (num<=9)
        {
            printf ("Stan wins.\n");
            Continue;
        }
        if (num>9&&num<=18)
        {
            printf ("Ollie wins.\n");
            Continue;
        }
    }
    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.