A Multiplication Game (博弈,规律)

本文介绍了一个简单的博弈论游戏,通过分析游戏规则找到了胜利条件的规律。游戏由两名玩家轮流进行,目标是通过特定的乘法操作使初始值首次超过给定阈值。文章通过实例展示了如何确定最终赢家。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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(1 < n < 4294967295),p=1,S和O游戏,两人轮流对p乘以2-9之间的一个数,首先使p>=n的人获胜,每次游戏都从S开始

分析:与其说博弈,不如说是规律。。 这个题看着有点像Nim博弈,想着和9的倍数? 还是别的?
写了一个,发现不对
然后根据题意列几个出来
S胜:2-9 (0+2)——9
O胜:10-18 (9+1)——9*2
S胜:19-162 (2*9+1)——9*2*9
O胜:163-324 (9*2*9+1)——9*2*9*2
S胜:324-2916 (9*2*9*2+1)——9*2*9*2*9
……

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
const double INF=0x3f3f3f3f+1.0;
const double eps=1e-6;
const double PI=2.0*acos(0.0);
typedef long long LL;
const int N=305;
int main()
{
    LL n,tmp;
    while(~scanf("%lld",&n))
    {
        if(n>1&&n<10) 
        {
            puts("Stan wins.");
            continue;
        }
        LL ans=0,p=1;
        while(p<n)
        {
 //           printf("p=%lld ans=%lld\n",p,ans);
            if(ans&1) p*=2;
            else p*=9;
            ans++;
        }
        printf("%s wins.\n",ans%2?"Stan":"Ollie");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值