题意:给定一个整数n,先手从1开始操作,谁先使这个数字>=n谁就获胜。操作:乘以2~9任意一个数。
分析:之前做的博弈都是将大数减小,这种博弈是变大,有点不同,但是博弈的基础理论还是不变的,设P(必败点),N(必胜点),那么初始有n~∞是必败点,那么能一步操作到达必败点为必胜点:n/9~n-1(/为向上取整),一步操作只能到达必胜点为必败点:n/9/2~n/9-1。最后只需要看1是必败还是必胜。PS:网上好多题解说要用浮点才能过。。那是因为他们直接用整除而忽略了余数的意义,所以只能用浮点过。
代码:
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=1000010;
const int MAX=1000000100;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=998244353;
const int INF=1000000010;
typedef double db;
typedef unsigned long long ull;
int main()
{
ll n;
while (scanf("%I64d", &n)!=EOF) {
while (n>18) n=n/18+n%18;
if (n<=9) printf("Stan wins.\n");
else printf("Ollie wins.\n");
}
return 0;
}