51nod 1070 Bash游戏 V4
来源:互联网 发布:linux centos 6.5 编辑:程序博客网 时间:2024/05/19 17:07
博弈论
修改 隐藏话题
1070 Bash游戏 V4
基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
收藏
关注
有一堆石子共有N个。A B两个人轮流拿,A先拿。每次拿的数量最少1个,最多不超过对手上一次
拿的数量的2倍(A第1次拿时要求不能全拿走)。拿到最后1颗石子的人获胜。假设A B都非常聪明
,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。
例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000)第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
Output
共T行,如果A获胜输出A,如果B获胜输出B。
Input示例
3234
Output示例
BBA
如果n是斐波那契的项数就输出B,否则输出A,打表找的规律,附打表程序
#include<cstdio>using namespace std;long long a[1000][1000];long long g[1000][1000];long long fib[100] = {1, 1};int tot = 0;bool dfs(int k, int n){if(n == 0) {return 0;}if(g[n][k] > 0) return a[n][k];g[n][k] = 1;int f = 0;for(int i = 1; i <= k + k; i++){if(i <= n) {if(dfs(i, n - i) == 0) f = 1;}}a[n][k] = f;return f;}int main(){long long T, n;for(tot = 2; fib[tot - 1] + fib[tot - 2] <= 1e9; tot++){fib[tot] = fib[tot - 1] + fib[tot - 2]; }/*printf("A ");for(int i = 1; i <= 100; i++){int flag = 0;for(int j = 1; j < i; j++){if(dfs(j, i - j) == 0) flag = 1;}if(flag == 0) printf("%d ", i); }*/scanf("%lld", &T);while(T--){scanf("%lld", &n);int flag = 0;for(int i = 1; i <= tot; i++){if(fib[i] == n) flag = 1;}if(flag == 1) puts("B");else puts("A");}return 0;}
阅读全文
0 0
- 51NOD 1070 Bash游戏 V4
- 51nod 1070 Bash游戏V4
- 51nod 1070 Bash游戏 V4
- 51nod 1070 Bash游戏 V4
- 51nod 1070 Bash游戏 V4
- 51nod-1070-Bash游戏 V4
- 51Nod-1070-Bash游戏 V4
- 51nod 1070 Bash游戏 V4 (博弈论_找规律)
- 51NOD 1070 Bash游戏 V4(斐波那契博弈)
- 51nod-1070 Bash游戏 V4(斐波那契博弈)
- 51NOD 1070 Bash游戏 V4(斐波那契博弈)
- 51nod 1070 Bash游戏 V4(博弈——找规律)
- 51 nod bash游戏
- 【51Nod1070】Bash游戏 V4
- 51nod1070(Bash游戏V4)
- 51nod Bash游戏(V1,V2,V3,V4(斐波那契博弈))
- 51nod 1066 Bash游戏
- 51nod 1066 Bash游戏
- Dropping Balls UVA
- kali->使用Metaspoit制作木马(无免杀)
- ImageNet 竞赛 2017 是最后一届,WebVision 竞赛或接棒
- C语言变量分类和应用以及五大内存空间
- linux下的文件操作命令
- 51nod 1070 Bash游戏 V4
- UVA 508 Morse Mismatches
- 招聘公告
- jQuery对象与DOM对象之间的转换方法
- padding 内边距
- Starting Tomcat v8.5 Server at localhost' has encountered a problem 的解决方法
- This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory
- LeetCode 11. Container With Most Water (Python)
- 盒模型、3d变换、关键帧动画