题干:

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.

解题报告:

   SG函数的方法目前还不会?

一个题解:

这里用一种推导的方法来进行求解

分析如下:Stan选2-9之间的数

如果是2,那么Ollie选的范围只能在4-18,这样Stan控制了19 - 4*9;

如果是3,那么Ollie选的范围只能在6-27,这样Stan控制了28 - 6*9;

如果是4,那么Ollie选的范围只能在8-36,这样Stan控制了37 - 8*9;

如果是5,那么Ollie选的范围只能在10-45,这样Stan控制了46 - 10*9;

如果是6,那么Ollie选的范围只能在12-54,这样Stan控制了55 - 12*9;

如果是7,那么Ollie选的范围只能在14-63,这样Stan控制了64 - 14*9; 如果是8,那么Ollie选的范围只能在16-72,这样Stan控制了73 - 16*9; 如果是9,那么Ollie选的范围只能在18-81,这样Stan控制了82 - 18*9;

 ===============

综上:

范围在2 – 9   是Stan win!(2-9)

范围在9+1 – 9*2   是Ollie win!(10-18)

范围在9*2+1 –9*2*9     是Stan win!(19-162)

范围在9*2*9+1 –9*2*9*2    是Ollie win!

范围在9*2*9*2+1 –9*2*9*2*9    是Stan win!

........

================

相信大家看得出规律了吧,范围左侧是上一个范围的右侧加一,右侧是上一个右侧交替的乘以2和9;

AC代码:

#include<cstdio>
#define ll long long
using namespace std;
ll n;
int main()
{
	while(~scanf("%lld",&n)) {
		ll cur = 1;
		bool flag = 0;//=1代表先手 
		while(cur<n) {//注意162这种边界,所以不能cur<=n
			if(!flag) {
				flag=1;
				cur*=9;
			}
			else {
				flag=0;
				cur*=2;
			}
		}
		if(flag) puts("Stan wins.");
		else puts("Ollie wins.");
	}
		
	return 0 ;
}

AC代码2:

题解

#include <stdio.h>
int main()
{
        double n;
        while(~scanf("%lf",&n))
        {
                while(n>18)
                        n/=18;
                if(n>=1&&n<=9)
                        printf("Stan wins.\n");
                else
                        printf("Ollie wins.\n");
        }
        return 0;
}