HDU1517 Multiply Game

Posted songorz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU1517 Multiply Game相关的知识,希望对你有一定的参考价值。

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. 

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 Input

162
17
34012226

Sample Output

Stan wins.
Ollie wins.
Stan wins.
题解:

由于每次都是从p=1开始的,所以只要判断每个游戏中1为必败点还是必胜点即可。(以下各式 / 均为取上整)
依照上面所提到的算法,将终结位置,即[n,无穷]标记为必败点;
然后将所有一步能到达此必败段的点标记为必胜点,即[n/9,n-1]为必胜点;
然后将只能到达必胜点的点标记为必败点,即[n/9/2,n/9-1]为必败点;
重复上面2个步骤,直至可以确定1是必胜点还是必败点。



参考代码:
技术分享图片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 ll n;
 5 int main()
 6 {
 7     while(~scanf("%lld",&n))
 8     {
 9         ll cnt=1;
10         for(int a=1;a;++a)
11         {
12             if(a&1) cnt=cnt*9ll;
13             else cnt=cnt*2ll;
14             if(cnt>=n)
15             {
16                 if(a&1) puts("Stan wins.");
17                 else puts("Ollie wins.");
18                 break;
19             }
20         } 
21     }
22     return 0;
23 }
View Code

 

以上是关于HDU1517 Multiply Game的主要内容,如果未能解决你的问题,请参考以下文章

Multiply game HDU-3074

hdu-3074 Multiply game---线段树+单点更新

HDU1517 A Multiplication Game

HDU 1517: kiki's game

HDU 1517 A Multiplication Game 博弈

hdu 1517 A Multiplication Game(必胜态,必败态)