博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
51NOD 1068 Bash游戏 V3
阅读量:4684 次
发布时间:2019-06-09

本文共 1063 字,大约阅读时间需要 3 分钟。

有一堆石子共有N个。A B两个人轮流拿,A先拿。每次拿的数量只能是2的正整数次幂,比如(1,2,4,8,16….),拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N,问最后谁能赢得比赛。

例如N = 3。A只能拿1颗或2颗,所以B可以拿到最后1颗石子。(输入的N可能为大数)
这是个博弈题。。我们可以先打个表看看
打表的过程如下

#include
#include
#include
#include
#include
#include
#include
using namespace std;const int N=1000000;int n; int dfs(int x,int pre){ if(x==0) return 0; for(int i=1;i<=n;i*=2) { if(x-i<0) break; if(dfs(x-i,i)==0) return 1; } return 0; }int main(){ while(scanf("%d",&n)!=EOF) { int flag=0; for(int i=1;i<=n;i*=2) { if(dfs(n-i,i)==0) { flag=1; break; } } if(flag) printf("n=%d:A ",n); else printf("n=%d:B ",n); } }

打完表我们可以知道B赢得情况是只有n能被3整除的时候。然后就很好做辣

#include
#include
#include
#include
#include
#include
#include
using namespace std;const int N=10000;char s[N];int main(){ int T,n; scanf("%d",&T); while(T--) { scanf("%s",s); n=0; int m=strlen(s); for(int i=0;i

转载于:https://www.cnblogs.com/NaCl/p/9580111.html

你可能感兴趣的文章
UML-画类图与交互图的顺序
查看>>
6月7 考试系统
查看>>
mysql 基本操作
查看>>
zTree async 动态参数处理
查看>>
Oracle学习之常见错误整理
查看>>
HTC Sensation G14开盒
查看>>
lock_sga引起的ksvcreate :process(m000) creation failed
查看>>
数据库插入数据乱码问题
查看>>
OVER(PARTITION BY)函数用法
查看>>
altium annotate 选项设置 complete existing packages
查看>>
【模式识别与机器学习】——SVM举例
查看>>
【转】IT名企面试:微软笔试题(1)
查看>>
IO流入门-第十章-DataInputStream_DataOutputStream
查看>>
DRF的分页
查看>>
html td 限制 高度 和 宽度
查看>>
mysql查询一个表的字段,添加或修改到另外一个表的数据
查看>>
CL.exe的 /D 选项, Preprocessor Macro预处理器宏定义
查看>>
[Pytorch]Pytorch中tensor常用语法
查看>>
ZOJ 1008 Gnome Tetravex
查看>>
Jenkin远程部署Tomcat8.5总结
查看>>