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<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<time.h>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#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<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> 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;
}

51 Nod 1067 博弈 SG函数的更多相关文章

  1. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  2. hdu 3032(博弈sg函数)

    题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...

  3. HDU-4678 Mine 博弈SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...

  4. (转)博弈 SG函数

    此文为以下博客做的摘要: https://blog.csdn.net/strangedbly/article/details/51137432 ---------------------------- ...

  5. 尼姆博弈+SG函数

    博弈这个东西真的很费脑诶.. 尼姆博奕(Nim Game):游戏者轮流从一堆棋子(或者任何道具)中取走一个或者多个,最后不能再取的就是输家.当指定相应数量时,一堆这样的棋子称作一个尼姆堆 当n堆棋子的 ...

  6. 【转】博弈—SG函数

    转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...

  7. HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)

    Fibonacci again and again Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & ...

  8. Light OJ 1199 - Partitioning Game (博弈sg函数)

    D - Partitioning Game Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  9. LightOJ 1315 - Game of Hyper Knights(博弈sg函数)

    G - Game of Hyper Knights Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...

随机推荐

  1. Cloudstack4.2之改变数据卷容量的大小(Resize Data Volumes)

    下图标注了这个功能在cloudstack4.2 UI中的位置 在cloudstack中是通过磁盘服务来设定卷的大小的.管理员可以设置相应的磁盘服务以供用户来使用.为了增强系统的灵活性,方便最终用户的使 ...

  2. STL中mem_fun, mem_fun_ref用法

    1.引言 先看一个STL中for_each的用法: #include <iostream> #include <vector> #include <algorithm&g ...

  3. chrome crx下载路径

    chrome crx下载后会被删除,可在检查时粘贴出来,下载路径在: %localappdata%\Google\Chrome\User Data\Webstore Downloads 参考:http ...

  4. tree.J48

    Weka为一个Java基础上的机器学习工具.上手简单,并提供图形化界面.提供如分类.聚类.频繁项挖掘等工具.本篇文章主要写一下分类器算法中的J48算法及事实上现. 一.算法 J48是基于C4.5实现的 ...

  5. Requests接口测试-对cookies的操作处理(二)

    我们继续来讨论一下cookie这方面的内容,我们都知道cookie是数据,一般的话在我接口测试中,数据都是要和代码进行分离的.本篇内容,我们队cookie内容进行处理,我们把登陆成功后的cookie写 ...

  6. mybatis所需pom文件内容以及配置文件

    官方网站http://www.mybatis.org/mybatis-3/zh/index.htmlpom文件<?xml version="1.0" encoding=&qu ...

  7. opencv—读取一张图片并滤波

    #include <opencv2\opencv.hpp> #include <iostream> #include <string> using namespac ...

  8. linux 管道与重定向

    命令行shell数据流有如下定义: 通过管道和重定向可以控制CLI的数据流

  9. var 在linq中的使用

    一:掌握linq,写出超炫的代码 1. var关键字 [隐式类型] 隐式类型 和 匿名类型的不同叫法. 特性 和 属性 2.隐式类型 就是让编译器来推断的一种语法糖. 二:隐式类型的应用场景 1. 简 ...

  10. touch和click优先性

    jQuery的touch事件是当用户触摸事件(页面)时触发的. jQuery的click事件是当用户点击元素时触发的. 而事件执行流程是手指点击一个元素,会经过:touchstart --> t ...