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;        
}

猜你喜欢

转载自www.cnblogs.com/MartinLwx/p/10126207.html
今日推荐