HDU 1517 a multiplication game (game & finding Rules)

Source: Internet
Author: User
A multiplication game

Time Limit: 5000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 3691 accepted submission (s): 2097


Problem descriptionstan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. stan always starts with p = 1, does his 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 is who first reaches P> = n.


Inputeach line of input contains one integer number n.


Outputfor each line of input output one line either

Stan wins.

Or

Ollie wins.

Assuming that both of them play perfectly.


Sample input1621734012226


Sample outputstan wins. Ollie wins. Stan wins.


Sourceuniversity of Waterloo local contest 2001.09.22


Recommendll is obtained by finding the regular because the starting p = 1, Stan wins when 2 <= n <= 9. If n is not 2 ~ If Ollie is about to win between 9, then if n is not greater than the minimum value that can be obtained, that is, 10 <= n <= 18 if n> 18, then we will analyze if s gets 2 for the first time, in this case, we can obtain that the range that O can select is [* 9]. We can see that the range that s can win is [* 9]. If s gets 3 for the first time, in this case, we can obtain that the range that O can select is [6, 3*9]. We can see that the range that s can win is [28, 6*9]. If s gets 4 for the first time, in this case, we can obtain that the range that O can select is [8, 4*9]. We can see that the range that s can win is [* 9]. If s gets 5 for the first time, then we can get that the range that O can select is [* 9]. We can get that the range that s can win is [* 9] If s gets 6 for the first time, then we can get that the range that O can select is [* 9]. We can get that the range that s can win is [* 9] If s gets 7 for the first time, then we can get that the range that O can select is [* 9]. We can get that the range that s can win is [64, 14*9]. If s gets 8 for the first time, then we can get that the range that can be selected by O is [* 9]. We can get that the range that can be won by S is [* 9]. If s gets 9 for the first time, the range that can be selected by O is [* 9], we can see that the second win range is [19,162*9], then we can get that the second win range is []. So [] s win [9 + * 9] o win [2*9 + * 9*9*9] s win [2*9*9 + * 9*9*2] o win can see that the right side of the range is multiplied by 2 and 9, on the left is the maximum value + 1 in the previous interval.
 1 #include<cstdio> 2 #include<cstring> 3 #include<stdlib.h> 4 #include<algorithm> 5 using namespace std; 6 int main() 7 { 8     __int64 n; 9     while(scanf("%I64d",&n)!=EOF)10     {11         int i=2,j=9;12         while(1)13         {14             if(i<=n&&n<=j)15             {16                 printf("Stan wins.\n");17                 break;18             }19             else20             {21                 i=j+1;22                 j=j*2;23                 if(i<=n&&n<=j)24                 {25                     printf("Ollie wins.\n");26                     break;27                 }28                 i=j+1;29                 j=j*9;30             }31         }32     }33     return 0;34 }
View code

 

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.