1067 Bash游戏 V2

有一堆石子共有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。

这道题可以来找规律
最重要的是找必败的点 我们以P表示必败态, N表示必胜态
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  16
P N P   N    N    N   N    P    N    P     N      N        N      N       P        N      P
这里最关键是找必败态,例如5,按1,3,4取,当取到3时,剩余2是让后手的必败态,所以先手必胜,例如7,按1,3,4,找不到让后手的必败态,那么先手必败。
依次类推,不难发现规律。
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<string>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<cstdio>
#define mes(x) memset(x, 0, sizeof(x))
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define INF 1e9+7
typedef long long ll;
using namespace std;
const int MAX = 101;
#define MOD 1000000007
#define fir first
#define sec second
//#define test
#define time
int main()
{
#ifdef test
    freopen("/home/ostreambaba/文档/input.txt", "r", stdin);
  //freopen("/home/ostreambaba/文档/output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    while(n--){
        int m;
        scanf("%d", &m);
        if(m%7 == 0 || m%7 == 2){
            cout << "B" << endl;
        }
            
        else{
            cout << "A" << endl;
        }
    }
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值