51NOD 1070 Bash游戏 V4
2016-07-22 21:48
309 查看
有一堆石子共有N个。A B两个人轮流拿,A先拿。每次拿的数量最少1个,最多不超过对手上一次拿的数量的2倍(A第1次拿时要求不能全拿走)。拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。
例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。
Bash游戏两连发。
还是打表找规律。通过打表我们可知当n为满足斐波那契数的时候。B才赢。
例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。
Bash游戏两连发。
还是打表找规律。通过打表我们可知当n为满足斐波那契数的时候。B才赢。
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<map> #include<set> #include<vector> using namespace std; const int N=10000; const int maxn=1e9+10; int f ; int n; int main() { f[0]=1; f[1]=1; int i; for(i=2;;i++) { f[i]=f[i-1]+f[i-2]; if(f[i]>maxn) break; } int T; scanf("%d",&T); while(T--) { scanf("%d",&n); int flag=0; for(int j=0;j<i;j++) { if(f[j]==n) { flag=1; break; } } if(flag) printf("B\n"); else printf("A\n"); } return 0; }
相关文章推荐
- shell--指“提供使用者使用界面”的软件(命令解析器)
- 菜鸟的Linux之路3 bash脚本编程之二
- Ubuntu 设定壁纸自动切换的shell脚本
- .bash_profile和.bashrc说明
- 使用shell操作mysql(转)
- linux shell 编程基础
- 使用shell实现打印给定日期的日历
- Linux shell脚本--mysql全备计划任务
- linux 性能数据采集bash脚本
- Best practice for Invoke other scripts or exe in PowerShell
- UVA 10152 ShellSort
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- HBase 常用Shell命令
- shell 十三问
- shell 中 getopts 用法
- [shell基础]——tr命令
- 「Shell」macOS系统下替换文件中的字符串
- Linux shell命令
- mac下创建.bash_profile步骤
- android中的HandlerThread类 Runtime.getRuntime()报错null environmentAndroid执行shell命令Android获取系统剩余可用内存信息