51nod 1067 Bash遊戲 V2 博弈

基準時間限制:1 秒 空間限制:131072 KB 分值: 10  難度:2級算法題
 收藏
 關注
有一堆石子共有N個。A B兩我的輪流拿,A先拿。每次只能拿1,3,4顆,拿到最後1顆石子的人獲勝。假設A B都很是聰明,拿石子的過程當中不會出現失誤。給出N,問最後誰能贏得比賽。
例如N = 2。A只能拿1顆,因此B能夠拿到最後1顆石子。
 
Input
第1行:一個數T,表示後面用做輸入測試的數的數量。(1 <= T <= 10000)
第2 - T + 1行:每行1個數N。(1 <= N <= 10^9)
Output
共T行,若是A獲勝輸出A,若是B獲勝輸出B。
Input示例
3
2
3
4
Output示例
B
A
A

Bash博弈的變形 Bash博弈變形以後基本變爲找規律的題 這題也不例外 打個表以後就能夠發現規律所在

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

int T;

int main() {
    scanf("%d", &T);
    while(T--) {
        int n;
        scanf("%d", &n);
        if(n % 7 == 0 || n % 7 == 2) printf("B\n");
        else printf("A\n");


    }

    return 0;
}
相關文章
相關標籤/搜索