HDU 1517 A Multiplication Game(博弈找规律)

来源:互联网 发布:剑桥少儿英语教学软件 编辑:程序博客网 时间:2024/05/11 18:06

传送门

A Multiplication Game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5309    Accepted Submission(s): 3021


Problem Description
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.

题目大意:

说给你一个数 n(n<4294967295), 开始有一个数 p,初始值为 1,现在有两个人在玩一个游戏,每次这个 p 可以乘以 29 中的任意一个数,

现在问你的是谁先让这个 np,谁就赢了。

解题思路:

这个题目,其实刚看到的时候也不知道怎么做。因为这也不能用 sg 来做,也不可以转化为 n 个游戏的异或和,那就再纸上分析吧,其实在纸上

画了画就发现规律了:

当这个 2n9 的时候,一定是先手胜;

当这个 91+1n92 的时候,一定是后手胜;

当这个 92+1n929 的时候,一定是先手胜;

当这个 929+1n9292 的时候,一定是后手胜;

当这个 9292+1n92929 的时候,一定是先手胜;

通过这些 我们就可以发现一个规律了,所以就可以进行操作了。

My Code

/**2016 - 08 - 31 晚上Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e4+5;const int MOD = 1e9+7;const double eps = 1e-7;const double PI = acos(-1);using namespace std;LL Scan_LL()///输入外挂{    LL res=0,ch,flag=0;    if((ch=getchar())=='-')        flag=1;    else if(ch>='0'&&ch<='9')        res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')        res=res*10+ch-'0';    return flag?-res:res;}int Scan_Int()///输入外挂{    int res=0,ch,flag=0;    if((ch=getchar())=='-')        flag=1;    else if(ch>='0'&&ch<='9')        res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')        res=res*10+ch-'0';    return flag?-res:res;}void Out(LL a)///输出外挂{    if(a>9)        Out(a/10);    putchar(a%10+'0');}int main(){    LL n;    while(cin>>n)    {        LL ans = 9LL, cnt = 0;        while(1)        {            if(ans >= n)                break;            if(cnt & 1)                ans *= 9;            else                ans *= 2;            cnt++;        }        if(cnt & 1)            puts("Ollie wins.");        else            puts("Stan wins.");    }    return 0;}
0 0
原创粉丝点击