1067 Bash游戏 V2 html
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题ios
收藏c++
取消关注算法
有一堆石子共有N个。A B两我的轮流拿,A先拿。每次只能拿1,3,4颗,拿到最后1颗石子的人获胜。假设A B都很是聪明,拿石子的过程当中不会出现失误。给出N,问最后谁能赢得比赛。测试
例如N = 2。A只能拿1颗,因此B能够拿到最后1颗石子。spa
Inputcode
第1行:一个数T,表示后面用做输入测试的数的数量。(1 <= T <= 10000) 第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
Outputhtm
共T行,若是A获胜输出A,若是B获胜输出B。
Input示例游戏
3 2 3 4
Output示例ip
B A A
#include<bits/stdc++.h> #include<stdio.h> #include<iostream> #include<cmath> #include<math.h> #include<queue> #include<set> #include<map> #include<iomanip> #include<algorithm> #include<stack> #define inf 0x3f3f3f3f using namespace std; typedef long long ll; bool f[8]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLIN f[1]=1;f[2]=0;f[3]=1;f[4]=1; f[5]=1;f[6]=1;f[7]=0; int t; int N; scanf("%d",&t); while(t--) { scanf("%d",&N); if(N<=7){puts(f[N]?"A":"B");continue;} else {puts(f[N%7==0?7:N%7]?"A":"B");continue;} } return 0; }