0
点赞
收藏
分享

微信扫一扫

51 Nod 1067 博弈 SG函数

沐之轻语 2022-05-27 阅读 29

1067 Bash游戏 V2

  1. 1 秒
  2. 131,072 KB
  3. 10 分
  4. ​​2 级题​​

  有一堆石子共有N个。A B两个人轮流拿,A先拿。每次只能拿1,3,4颗,拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。 例如N = 2。A只能拿1颗,所以B可以拿到最后1颗石子。    

输入

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

输出

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

输入样例

3
2
3
4

输出样例

B
A
A

1e9过大,打表找规律;

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
#define mclr(x,a) memset((x),a,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-5
typedef pair pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair pii;

inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}


ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; }



/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/

int f[maxn];
int SG[maxn], S[maxn];

void sg(int n) {
// int i, j;
ms(SG);
for (int i = 1; i <= n; i++) {
ms(S);
for (int j = 1; f[j] <= i && j <= 3; j++) {
S[SG[i - f[j]]] = 1;
}
for (int j = 0;; j++)if (!S[j]) {
SG[i] = j; break;
}
}
}

int main()
{
// ios::sync_with_stdio(0);
f[1] = 1; f[2] = 3; f[3] = 4;
/* sg(100); int ans = 0;
for (int i = 1; i <= 100; i++) {
cout << i << ' '; ans = SG[i];
if (ans)cout << "A" << endl;
else cout << "B" << endl;
}
*/
int T = rd();
while (T--) {
int n = rd();
if (n % 7 == 0 || ((n - 2) % 7 == 0)) {
puts("B");
}
else puts("A");
}
return 0;
}

 

EPFL - Fighting

举报

相关推荐

0 条评论