POJ 2505 Multiplication Game

Source: Internet
Author: User

Test instructions: Stan starts at 1 and can multiply any number in the 2~9, and Ollie is doing the same, only to someone who has done more than N for this turn. 1<n<2^32-1

Find Stan's losing state, [10,18],[163,324] ... [9^n*2^ (n-1) +1,9^n*2^n] ...


Starting from 1, no matter how Stan operates, Ollie the pattern into a balanced state [9^1*2^0+1,9^1*2^1] ([10,18]) and no matter how Stan goes, Ollie the pattern into equilibrium [9^n*2^ (n-1) +1,9^n*2^n] However, the only thing Stan can do in a balanced state is to break the balance, so if n is in a state of equilibrium, Ollie will win; otherwise Stan wins.

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main ()
{
    int n;
    while (Cin>>n)
    {
        bool count=false;
        while (n>9| | count==true)//N<=9 exit the loop
        {
            if (count%2==0)
                n= (n%9!=0)
            when the current state is a must-fail state? N/9+1:N/9; else
                n= (n%2!=0)? N/2+1:N/2;
            Count=!count;
        }
        if (n!=1)
            cout<< "Stan wins." <<endl;
        else
            cout<< "Ollie wins." <<endl;
    }
}


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.