题目地址:HDU 1517
NP状态转换。
可以把题目的向上乘变成向下除。这样1是终结状态,设1的时候为必败点。
根据所有能一步到达必败点的点是必胜点,所以[x,x*9]必胜点;根据只能到达必胜点的点是必败点,所以[x*9+1,x*9*2]是必败点.
然后求解。
代码如下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define LL __int64
int main()
{
LL n, x;
int f;
while(scanf("%I64d",&n)!=EOF)
{
x=1;
f=0;
while(x<n)
{
if(!f)
x*=9;
else
x*=2;
f=1-f;
}
if(!f)
puts("Ollie wins.");
else
puts("Stan wins.");
}
return 0;
}