51nod-1070-Bash游戏 V4
来源:互联网 发布:linux 网络编程本地ip 编辑:程序博客网 时间:2024/05/18 03:19
题目描述
有一堆石子共有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
3
2
3
4
output
B
B
A
题解
典型的斐波那契博弈
http://blog.csdn.net/dgq8211/article/details/7602807
卖个安利可以好好看看这个大大写的证明
中心思路:
1、如果x为斐波那契数,必败,输出B
2、如果x不是斐波那契数,必胜,输出A
证明链接里有quq
然后贴代码(本来想直接开个数组没想到内存爆了t t)
var n,x,i:longint; f:array[0..1000000005] of boolean;function check(x:longint):boolean;var t,a,b:longint;begin a:=1;b:=1; if x=1 then exit(true); while (a+b<1000000000) do begin t:=a;a:=b;b:=t+a; if t=x then exit(true); end; exit(false);end;begin readln(n); for i:=1 to n do begin readln(x); if check(x) then writeln('B') else writeln('A'); end;end.
阅读全文
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游戏
- keras: Why is the training loss much higher than the testing loss?
- gdb的基础详细用法
- 求1+2+3.+...
- top和ps取长补之自定义要显示的字段列表
- CF450B——水矩阵
- 51nod-1070-Bash游戏 V4
- win7基础 cmd del+*.扩展名 删除指定文件夹下的同一类型的所有文件
- Spring Cache抽象-缓存管理器
- 常见的机器学习&数据挖掘知识点
- python 参数及简单文件操作
- c/c++无结束标志时,输入一串int型
- QT之QApplication的exit,quit调用后仍然显示窗口
- kafka server.properties配置文件
- win7基础 显示出文件的扩展名