1. 程式人生 > >Hdoj 1517.A Multiplication Game 題解

Hdoj 1517.A Multiplication Game 題解

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.

Sample Input

162
17
34012226

Sample Output

Stan wins.
Ollie wins.
Stan wins.

Source

University of Waterloo Local Contest 2001.09.22


思路

跟巴什博奕不同的是,這裡是乘法,但是思路差不多

可取區間在\([2,9]\),顯然如果這是Stan的必勝段,而\([10,18]\)是Stan的必敗段,這樣一次博弈就完成了,後面的狀態要得出來也可以,\([19,162]\)為Stan的必勝段,更後面的情況可以歸結到\([1,18]\)的討論(巴什博奕也是歸結到前(1+m))的討論

上線分別是乘以2,9在變化是因為兩個人的擴張策略不一樣,Stan先手肯定是儘量乘以大的贏得概率大,從Ollie的角度想,就要乘以小的來儘可能阻止Stan贏

程式碼

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double n;
    while(cin >> n)   
    {       
        while(n>18)  n/=18;       
        if(n<=9)
            cout << "Stan wins.\n";       
        else  
            cout << "Ollie wins.\n";   
    }           
    return 0;        
}