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。


直接打表,bool类型,在三个操作都无法达到对手的必败态的时候,此点必败。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
#define MAXN 100000009
typedef long long LL;
bool a[MAXN];
/*
A B两个人轮流拿,A先拿。每次只能拿1,3,4颗,拿到最后1颗石子的人获胜
必胜 1,3,4,
1 2 3 4 5 6 7 8 9 10
A B A A A A B A B A
*/
void init()
{
    a[1] = a[3] = a[4] = true;
    a[2] = false;
    for(LL i=5;i<MAXN;i++)
    {
        if(a[i-1]&&a[i-3]&&a[i-4])
            a[i] = false;
        else
            a[i] = true;
    }
}
int main()
{
    init();
    LL t,n;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&n);
        if(a[n])
            printf("A
");
        else
            printf("B
");
    }
    return 0;
}
有简便解法找规律,n%7==0 or n%7==2,B
原文地址:https://www.cnblogs.com/joeylee97/p/6276811.html