A Multiplication Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7442 Accepted Submission(s): 4213
Problem Description
Stan 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.
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.
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.
题意:给出一个n,要求每人每次在p的基础上乘2-9之间的数,第一个使结果大于等于n的人获胜,p初始为1
题解:巴什博弈的变形,先手想赢的话就应该要多乘2,要让后手输就多乘9. emmmm 没毛病
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() { 4 long long n; 5 while(~scanf("%lld",&n)) 6 { 7 long long sum=1; 8 for(int i=1;i++;) 9 { 10 if(sum>=n) 11 { 12 sum=i;break; 13 } 14 if(i%2) 15 { 16 sum*=2; 17 } 18 else 19 { 20 sum*=9; 21 } 22 23 } 24 25 if(sum%2)printf("Stan wins. "); 26 else printf("Ollie wins. "); 27 } 28 return 0; 29 }