0
点赞
收藏
分享

微信扫一扫

51nod-1070 Bash游戏 V4(斐波那契博弈)


原题链接




1070 Bash游戏 V4



基准时间限制:1 秒 空间限制:131072 KB 分值: 40  难度:4级算法题



 收藏

 关注

有一堆石子共有N个。A B两个人轮流拿,A先拿。每次拿的数量最少1个,最多不超过对手上一次拿的数量的2倍(A第1次拿时要求不能全拿走)。拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。


例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。


Input


第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000)第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)


Output


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


Input示例


3234


Output示例


BBA



如果N是斐波那契数则为必败态

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#define maxn 100005
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll f[55];
int main(){
	
//	freopen("in.txt", "r", stdin);
	f[0] = 0;
	f[1] = 1;
	for(int i = 2; i <= 50; i++){
	  f[i] = f[i-1] + f[i-2];
    }
    
    int t, n;
    scanf("%d", &t);
    while(t--){
    	int sign = 0, i;
    	scanf("%d", &n);
    	for(i = 1; i <= 50; i++){
    		if(n == f[i]){
    			puts("B");
    			sign = 1;
    			break;
    		}
    	}
    	if(sign == 0)
    	 puts("A"); 
    }
    return 0;
}




举报

相关推荐

0 条评论