【Luogu】P2953牛的数字游戏(博弈论)
自己乱搞……然后一遍AC啦!
思路从基本的必胜态和必败态开始分析。我们把减去最大数得到的数叫作Max,减去最小数得到的数叫作Min。
那么开始分析。
一、0是必败态。
这个没法解释。题目就这么定义的。
二、若一个数的Max和Min都是必胜态,那该数为必败态。
如果你拿到一个数,结果你发现怎么减都会让对手必胜,那恭喜你,你拿到了一个必败的数。很好理解。
三、若一个数的Max和Min有一个是必败态,那该数为必胜态。
如果你拿到一个数,发现有一种减法让对手从此无法翻盘,那恭喜你,你拿到了一个可以必胜的数。
根据这三条原则就很好设计啦
设f[x]判断x是必胜态还是必败态。从小到大枚举,按上面三条原则乱搞搞就可以O1查询啦。
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<algorithm> using namespace std; inline long long read(){
long long num=,f=;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') f=-;
ch=getchar();
}
while(isdigit(ch)){
num=num*+ch-'';
ch=getchar();
}
return num*f;
} struct Point{
int maxn,minn;
Point(){ maxn=-;minn=; }
}; inline Point getlen(int val){
Point ans;
while(val){
int x=val%; val/=;
if(!x) continue;
ans.maxn=max(ans.maxn,x);
ans.minn=min(ans.minn,x);
}
return ans;
} int f[];
bool vis[]; void dfs(int val){
if(vis[val]) return;
vis[val]=;
if(val==) return;
Point now=getlen(val);
if(!vis[val-now.maxn]) dfs(val-now.maxn);
if(!vis[val-now.minn]) dfs(val-now.minn);
if((f[val-now.maxn]==)||(f[val-now.minn]==)) f[val]=;
} int main(){
int T=read();
for(int i=;i<=;++i)
if(!vis[i]) dfs(i);
while(T--){
int n=read();
if(f[n]) printf("YES\n");
else printf("NO\n");
}
return ;
}
【Luogu】P2953牛的数字游戏(博弈论)的更多相关文章
- 洛谷 [P2953] 牛的数字游戏
SG搜索 n的范围在可以接受的范围内,SG搜索即可 #include <iostream> #include <cstdio> #include <cstring> ...
- 洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, ...
- [USACO09OPEN]牛的数字游戏Cow Digit Game 博弈
题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve vict ...
- LuoguP2953 [USACO09OPEN]牛的数字游戏Cow Digit Game(博弈论)
1~9显然,后面平\(A\)过去 #include <iostream> #include <cstdio> #include <cstring> #include ...
- 【Luogu】P3708Koishi的数字游戏(数论)
题目链接 考虑f(i)=i%1+i%2+i%3+.....+i%n f(i+1)=(i+1)%1+(i+1)%2+......+(i+1)%n 其中不是i+1的因数的部分在f(i+1)的地方都加了1. ...
- 【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 写挫好几次.... 裸的博弈论即可.. #include <cstdio> #in ...
- luogu P1043 数字游戏
题目描述 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易.游戏是这样的,在你面前有一圈整数(一共n个),你要按顺序将其分 ...
- BZOJ1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5 ...
- 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 72 Solved ...
随机推荐
- ios自定义日期、时间、城市选择器
选择器,我想大家都不陌生,当需要用户去选择某些范围值内的一个固定值时,我们会采用选择器的方式.选择器可以直观的提示用户选择的值范围.统一信息的填写格式,同时也方便用户快速的进行选择,比如对于性别,正常 ...
- Flask应用运行流程
当我们运行项目后,Flask内部都经历了什么 1.app.run()启动项目,ctrl点进源码 app.py: 1)执行了run_simple() 2)注意第三个参数,这里是Flask实例化的对象,在 ...
- docker配置国内镜像
1. 配置 root@ros-OptiPlex-3050:~# cat /etc/docker/daemon.json { "graph": "/mnt/docke ...
- JavaScript实现的水果忍者游戏,支持鼠标操作
智能手机刚刚普及时,水果忍者这款小游戏可谓风靡一时.几年过去了,现在,让我们用纯JavaScript来实现这个水果忍者游戏,就算是为了锤炼我们的JavaScript开发技能吧. 大家可以通过这个链接在 ...
- cannot load such file -- bundler/setup解决
sudo gem install bundler bundle update celluloid
- java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal问题解决
使用Maven构建项目并加载spring配置文件时,报如下异常 Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTrav ...
- nginx的web基础
基于nginx的web部署 [root@nginx ~]# cd /data/web/ client_body_temp/ conf/ fastcgi_temp/ html/ logs/ proxy_ ...
- Kernel Stack Overflow(转)
0x00 漏洞代码 stack_smashing.c #include <linux/init.h> #include <linux/module.h> #include &l ...
- xheditor的实例程序—类似word的编辑器
编辑器工具栏:类似word的编辑器 1.1.下载,兼容性 xhEditor官方网站地址为:http://xheditor.com/,打开右上角的免费下载 | 参数向导链接,即可找到最新版本的下载地址. ...
- 创建yum仓库
第1章 服务端)创建yum仓库目录 命令:(创建)mkdir -p /application/yum/centos6.6/x86_64/ 命令:(切换)cd /application/yum/cent ...