「 POJ2505 」 A multiplication game [game Theory], poj2505 」

Source: Internet
Author: User

「 POJ2505 」 A multiplication game [game Theory], poj2505 」

Question link: http://poj.org/problem? Id = 2505

Question:

Two people play the game in turn. Stan starts with the number p starting from 1. Stan multiplied by a number of 2-9, and Ollie multiplied by a number of 2-9, it is not until the person who first multiply p to p> = n wins, and when it is his or her turn, someone must multiply by 2-9.

Solution:

This is a question of game theory.
However, this question does not involve knowledge about SG functions.
First, we can quickly determine that the interval [2, 9] must be a first-hand victory.
Then the interval [10, 18] is followed by the victory
What then?
[18,?]
We can understand this as follows:
We can consider that the first hand is to win, that is, the bigger the better, the faster the bigger,
So each time it is the first hand to perform the operation, it must be the maximum number to multiply, that is, 9
In turn, the latter hand is to hold the first hand as much as possible, so each time the smallest number is multiplied, that is, 2
Then, we can make up the interval:
[2, 9]
[9 + 1, 9*2]
[9*2 + 1, 9*2*9]
[9*2*9 + 1, 9*2*9*2]
.......
So we can do a question.
As for how to operate, the method I use is not the fastest, but it should be clear.
Define l, r to 2, 9, and then follow the above simulation, and then each judgment will be done
Amount... I have questions on the Internet and explained that they have found a rule. I don't even find a rule ..... It took a long time to launch...
Speechless...
Code:

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 typedef long long ll; 6 ll n; 7 int main() 8 { 9     while(scanf("%lld",&n)==1)10     {11         ll l=2;12         ll r=9;13         int flag=1;14         while(true)15         {16             if(n>=l&&n<=r)17             {18                 if(flag==1)  printf("Stan wins.\n");19                 else         printf("Ollie wins.\n");20                 break;21             }22             else{23                 l=r+1;24                 if(flag==1) 25                 {26                     r=r*2;27                     flag=0;28                 } 29                 else30                 {31                     flag=1;32                     r=r*9;33                 }34             }35         }36     }37     return 0;38 }

Thank you for your support.

I am very grateful for how I can point out what I have written badly !!

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.