找到Stan的必败状态,[10,18],[163,324]……[9^n*2^(n-1)+1,9^n*2^n]
分析:
0-9:stan
10-18:ollie
19-162:stan
163-324:ollie
规律:
9 = 9
18 =2*9
162 = 9*2*9
324 = 2*9*2*9
...
代码如下:
#include<iostream> #include<cstdio> using namespace std; double n; int main() { while(scanf("%lf",&n)!=EOF) { while(1) { if(n<=9){printf("Stan wins.\n");break;} else if(n<=18){printf("Ollie wins.\n");break;} n/=18; } } return 0; }