Uva 847 Solution

It turns out that the optimal strategy for Stan to win is to always multiply p with 9 (the largest
possible) so that he can reach p ≥ n as fast as possible (the target number) while Ollie will always
multiply p with 2 to prevent Stan from reaching p ≥ n.

Numerical value or log18(base) and depending on Stan’s highest and Ollie’s lowest value.

0 < n < 9 => Stan winner,

9  * 2 = > [10, 18] => Ollie winner    [   0.79 <  n < 1]

9 * 2 * 9 =>[19, 162] => Stan  [1.0187  < n < 1.760188]

9 * 2 * 9 * 2 =>[163, 324] => Ollie [ 1.7623167 < n < 2]

9 * 2 * 9 * 2 * 9 =>[325,2916] => Stan [ 2.001066183 < n < 2.760187533]

9 * 2 * 9 * 2 * 9 * 2 => [2917, 5832] => Ollie    [same  process ]

9 * 2 * 9 * 2 * 9 * 2  * 9 [ 5833,52488]  =>  Stan [ same   process]

9 * 2 * 9 * 2 * 9 * 2  * 9 * 2[52489,104976] => Ollie [Same  process ]

9 * 2 * 9 * 2 * 9 * 2  * 9 * 2 * 9 [104977,944784] = > Stan  [same process ]

9 * 2 * 9 * 2 * 9 * 2  * 9 * 2 * 9 * 2[944785, 1889568] = > Ollie [same process]

9 * 2 * 9 * 2 * 9 * 2  * 9 * 2 * 9 * 2 * 9[1889569,17006112] = > Stan [same process]

9 * 2 * 9 * 2 * 9 * 2  * 9 * 2 * 9 * 2 * 9 * 2[17006113, 34012224] = > Ollie [Same process]

9 * 2 * 9 * 2 * 9 * 2  * 9 * 2 * 9 * 2 * 9 * 2 * 9[34012225, 306110016] = > Stan [same process]

9 * 2 * 9 * 2 * 9 * 2  * 9 * 2 * 9 * 2 * 9 * 2 * 9 * 2[306110017, 612220032] = > Ollie [same process]

9 * 2 * 9 * 2 * 9 * 2  * 9 * 2 * 9 * 2 * 9 * 2 * 9 * 2  * 9[612220032,5509980288]  => Stan [same process]


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n;
    while(cin >> n)
    {
        ll p = 1;
        int i = 1;
        while(p<n)
        {
            if(i%2 == 1)
                p = p*9;
            else
                p = p*2;
            if(p>=n)
                break;
            i++;
        }
        if(i%2 == 1)
            cout << "Stan wins." << endl;
        else
            cout << "Ollie wins." << endl;
    }
    return 0;
}

Comments