B - A Multiplication Game HDU - 1517

本文深入解析了一款基于整数乘法的博弈游戏算法,详细阐述了游戏规则及获胜策略,通过实例输入输出展示了游戏过程,并附带了C++代码实现。

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.

写完这个题就睡觉觉啦,嘿嘿
这的确是一个稍有难度博弈的问题(这个可不属于博弈中的任何一个):

游戏规则为:两个人在2-9选数选出之后与p相乘,此时p=p*(2…9);当p>=n时这一方获胜。
如果输入是 2 ~ 9 ,(2~9)因为Stan 是先手,所以Stan 必胜
如果输入是 10~18 ,(9+1~92)因为Ollie 是后手,不管第一次Stan 乘的是什么,Stan肯定在 2 ~ 9 之间,如果Stan乘以 2 ,那么Ollie就乘以 9 ,就到18了,如果Stan乘以 9 ,那么Ollie乘以大于1的数都都能超过 10 ~ 18 中的任何一个数。Ollie 必胜
如果输入是 19 ~ 162,(9
2+1~929)那么这个范围是 Stan 的必胜态

如果输入是 163 ~ 324 ,(929+1~929*2)这是又是Ollie的必胜态


本文来自 深度抽象 的优快云 博客 ,全文地址请点击:https://blog.youkuaiyun.com/wwwzys/article/details/6716422?utm_source=copy
代码给上:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

ll n;
ll p;
ll countt;

int main()
{
	while(scanf("%lld",&n)!=EOF)
	{
		countt=0;
		p=1;
		while(1)
		{
			if(p>=n) break;
			countt++;
			if(countt&1) p*=9;
			else p*=2;
		}
		printf("%s\n",countt&1?"Stan wins.":"Ollie wins.");
	}
}

努力加油a啊,(o)/~。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值