HDU 1517 A Multiplication Game 博弈

题目大意:从1开始Stan与Ollie经行博弈,stan先手,每次将当前数乘上(2~9)间的任意数,最后一次操作后大于等于n的人获胜。

题目思路:

1-9 stan 胜 10-18 ollie胜

19-162 stan 胜 163-306 ollie胜 (stan为了接近那个数尽可能的扩大选择乘9,ollie知道自己无法在一步内获胜,为了避免stan获胜所以乘上最小的数2,接下来stan最大可以到达的数为乘上9后的数:162)

……

胜负区间对称!

#include<stdio.h>
#include<cmath>
#include<string.h>
#include<iostream>
#include<algorithm>
#define MAXSIZE 1005
#define LL long long
using namespace std;

int Check(int n)
{
    double m=n;
    while(m>18)
    {
        m/=18;
    }
    if(m<=9) return 1;
    return 0;
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int op=Check(n);
        if(op) printf("Stan wins.
");
        else printf("Ollie wins.
");
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/alan-W/p/6278122.html