博弈题。
初始时p=1,可以从2-9中任选一个数与之相乘,给定一个数n,当最先令p>=n的为获胜。
可以知道,当ceil(n/9)时为必胜状态,那么,必败状态只能转往必胜状态,所以,(ceil(n/9)/2)的只能是必败状态。倒推回去,就能知道先手处在必胜还是必败状态了。
#include <iostream>
#include <cstdio>
#include <algorithm>
#define LL __int64
using namespace std;
int main(){
LL n;
while(scanf("%I64d",&n)!=EOF){
bool win=false;
if(n==1){
printf("Stan wins.\n");
continue;
}
while(n>1ll){
if(!win){
LL t=n/9;
if(t*9<n) n=t+1;
else n=t;
}
else{
LL t=n/2;
if(2*t<n) n=t+1;
else n=t;
}
// cout<<n<<endl;
win=!win;
}
if(win) printf("Stan wins.\n");
else printf("Ollie wins.\n");
}
return 0;
}