博弈论——巴什博弈

基础巴什博弈:

有一堆石子共有N个。A B两个人轮流拿,A先拿。每次最少拿1颗,最多拿K颗,拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N和K,问最后谁能赢得比赛。

例题 :51NOD - 1066 Bash游戏

#include<bits/stdc++.h>
using namespace std;
#define LL long long

const int MAX = 1e6+10;
const int INF = 0x3fffffff;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,k;
        scanf("%d%d",&n,&k);
        if(n%(k+1)==0){
            printf("B\n");
        }
        else printf("A\n");
    }
    return 0;
}

进阶巴什博弈

有一堆石子共有N个。A B两个人轮流拿,A先拿。每次只能拿1,3,4颗,拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。

例题:51NOD - 1067 Bash游戏 V2

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-----------------"<<endl;

typedef long long ll;
const int maxn = 1e5+10;
const int MAXN = 1e6+10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int N = 1010;


int main(){
	int T ;
	scanf("%d", &T);
	while(T--){
		ll n;
		scanf("%lld", &n);
		ll t = n % 7;
		if(t == 0 || t == 2) cout << "B" << endl;
		else cout << "A" << endl;
	}
	return 0;
}

例题:51NOD - 1068 Bash游戏 V3

遇事不决先打表:

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20

A   A   B   A   A   B   A   A  B    A    A     B     A     A     B     A     A     B    A     A

发现规律:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-----------------"<<endl;

typedef long long ll;
const int maxn = 1e5+10;
const int MAXN = 1e6+10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int N = 1010;


int main(){
	int T;
	scanf("%d", &T);
	while(T--){
		char s[N];
		int sum = 0;
		scanf("%s", s);
		int len = strlen(s);
		for(int i = 0; i < len; i++){
			sum += (s[i] - '0');
		}
		if(sum % 3 == 0) puts("B");
		else puts("A");
	}
	return 0;
}

例题:51NOD - 1070 Bash游戏 V4

表面巴什博弈,斐波那契博弈的板子题

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define line cout<<"-----------------"<<endl;

typedef long long ll;
const int maxn = 1e5+10;
const int MAXN = 1e6+10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int N = 1010;

ll a[N];
void init(){
    a[0] = a[1] = 1;
    for(int i = 2; i <= 60; i++){
        a[i] = a[i-1] + a[i-2];
    }
}

int main(){
	init();
	int T;
	scanf("%d", &T);
	while(T--){
		ll n;
		scanf("%lld", &n);
		int flag = 1;
		for(int i = 1; i <= 60; i++){
			if(a[i] == n){
				flag = 0;break;
			}
		}
		if(flag) puts("A");
		else puts("B");
	}
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值