51Nod - 1066 Bash游戏 (bash博弈)

1066 Bash游戏

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题

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

例如N = 3,K = 2。无论A如何拿,B都可以拿到最后1颗石子。

Input

第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行2个数N,K。中间用空格分隔。(1 <= N,K <= 10^9)

Output

共T行,如果A获胜输出A,如果B获胜输出B。

Input示例

4
3 2
4 2
7 3
8 3

Output示例

B
A
A
B

bash博弈:共有n个,a,b每个人最多取k个,取到zu最后一个的人赢,无论先手怎么取,后手都可以取m个,使得与先手加起来为k+1;

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;

int main()
{
    int t,n,k;
    cin>>t;
    while(t--){
        cin >> n>>k;//无论先手怎么取,后手都可以取m个,使得和先手的和为k+1
        if(n%(k+1)==0)
            cout<<'B'<<endl;
        else
            cout<<'A'<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42754600/article/details/81213301
今日推荐