黑龙江大学程序设计竞赛(重现赛)- Bash Game - Bash博弈变形(详解)

题目描述

The two new cute boys(Alice and Bob) in the ACM group of HLJU science and technology association have been dreaming of getting these six books written by Mr Jin.

 

As we all know, there is no such thing as a free lunch. Mr Jin now lets Alice and Bob play a game,and only the winner of the game can get these six books.The rules of the game are as follows.

 Suppose(假设) the price of these six books is P, two people take turns in bidding(竞拍), Suppose one party(一方) bid A yuan during the bidding process and the other party(另一方) bid B yuan. Rules require . In this way, the bidding goes on in turn until the price of one party is greater than or equal toP,the party fails and the game ends, Mr Jin awarded these books to another party.

 

Alice first bid, Bob bid behind him every time, and Alice and Bob use the best strategy(最优策略), who can get these books?

输入描述:

输出描述:

示例1

输入

复制

4
1 1
20 6
10 2
23 7

输出

复制

Bob
Alice
Bob
Alice

思路:

这个题是bash博弈的变形。

可以看成有一堆石子,石子数为p,这次报一个数A,那么下次报的数范围是[A+1,A+M](第一次报的数范围[1,M],可看成第0次报了0)

那么举个例子:p=10,m=4

第一次报的范围[1,4]   若报3    差值为3

第二次报的范围[4,7]   若报5    差值为2

第三次报的范围[6,9]   若报9    差值为4

第四次报的范围[10,13]   若报10    差值为1

3+2+4+1=10

相当于一个p个石子,两人轮流取,每次取[1,M]个,然后最后取走的失败,问谁失败(Bash博弈变形)

后手能保证每一轮他取完后,取的石子数总数都是M+1的倍数,

(1)p%(M+1)==1,A必败,B每轮都与A凑够m+1个,最后剩给A 1个

(2)否则,A必胜

  • p%(m+1)==0,第一轮,A取m个,剩下每次B取一个,A都和他凑成M+1个,经过多次BA,BA取后,B剩下了1个
  • p%(m+1)>1,设p%(m+1)=k;那么A先取k-1个,那么此时:p%(m+1)==1,该B取了,就相当于(1)这种情况,B必败

代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const int N=100010;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int p,m;
        scanf("%d%d",&p,&m);
        if(p%(m+1)==1){
            printf("Bob\n");
        }
        else printf("Alice\n");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值