【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404
写挫好几次。。。。
裸的博弈论即可。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1000005;
bool f[N], vis[N];
bool dfs(int x) {
if(vis[x]) return f[x];
if(x==0) return 0;
vis[x]=1;
int t=x, mx=0, mn=10;
while(t) {
int k=t%10;
t/=10;
if(k) mx=max(mx, k), mn=min(mn, k);
}
if(!dfs(x-mn)) return f[x]=1;
if(!dfs(x-mx)) return f[x]=1;
return f[x]=0;
}
int main() {
int n=getint();
while(n--) {
int ans=dfs(getint());
ans?puts("YES"):puts("NO");
}
return 0;
}
Description
Input
Output
Sample Input
9
10
Sample Output
NO
HINT
For the first game, Bessie simply takes the number 9 and wins.
For the second game, Bessie must take 1 (since she cannot take 0), and then
FJ can win by taking 9.
Source
【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)的更多相关文章
- BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
一开始被题意坑了= =,题目是说这个数字的最大和最小,不是个位的最大和最小= = 不知道怎么做只能递推了,必胜态就是存在能到达必败态的,必败态就是只能到达必胜态的 CODE: #include< ...
- 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 72 Solved ...
- BZOJ3404: [Usaco2009 Open]Cow Digit Game又见数字游戏
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 47 Solved ...
- 【博弈论】【SG函数】bzoj3404 [Usaco2009 Open]Cow Digit Game又见数字游戏
#include<cstring> #include<cstdio> #include<algorithm> #include<set> using n ...
- 【BZOJ】【3404】【USACO2009 Open】Cow Digit Game又见数字游戏
博弈论 Orz ZYF 从前往后递推……反正最大才10^6,完全可以暴力预处理每个数的状态是必胜还是必败(反正才两个后继状态),然后O(1)查询……我是SB /******************** ...
- BZOJ1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 5 ...
- BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛( deque )
直接用STL的的deque就好了... ---------------------------------------------------------------------- #include& ...
- BZOJ 3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 动态规划
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=34 ...
- BZOJ 3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队:dp【和为f的倍数】
题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1375 题意: 给你n个数,你可以从中选任意多个,但不能不选.问你所选数字之和为f的倍数 ...
随机推荐
- Discuz常见小问题2-如何修改整个网站的默认字体为微软雅黑
界面-风格管理,然后点击默认模板的编辑,在正常字体和小号字体前面加上你要的字体(比如微软雅黑,XXX,XXX),挨个排到后面,如果前面的字体没有则显示后面的 修改之后的效果(注意你不要在页面定义别的C ...
- PhoneGap录像 以及 录音功能 简单代码实现3
1,录音功能 navigator.device.capture.captureAudio( function(files){//成功回调函数 Ext.getCmp("video_files_ ...
- kindeditor 图片上传插件
富文本编辑器,kindeditor是比较好用的一款.需要的功能都有,文档.demo也详细.有什么功能去官网看一眼就好. 官网:http://kindeditor.net/ 一些好用的如图片上传,kin ...
- Gradle在Android中的基本使用
1.基本概念 程序开发作为一种工程作业,不光是编写代码,还涉及到工程的各种管理(依赖,打包,部署,发布,各种渠道的差异管理.....).很多时候,我们反复的build,clean,签名,打包,发布,那 ...
- 微信小程序 (node) warning: possible EventEmitter memory leak detected
小程序 (node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setM ...
- CLR_Via_C#学习笔记之事件
一:首先我先引用网上别人对事件的一些说明,然后将会通过一个事例进行对事件的演示: EventArgs是包含事件数据的类的基类,用于传递事件的细节.EventHandler是一个委托声明如下 publi ...
- mongodb安装的两条命令
1. 安装 下载并安装,注意安装方式为custom,路径自定义(d:\chengxu\mongodb),安装成功后在mongodb文件夹下新建data文件夹(内新建db文件夹)和logs文件夹(内新建 ...
- Git-在一个电脑上同时使用两个Git的账号
前言 又需要登录公司的账号,又想在电脑上使用自己的账号. 实现 首先是git config方面的设置,要取消掉原本对于git账号的全局设置. git config --global --unset u ...
- Linux-profile、bashrc、bash_profile之间的区别和联系
为使Bash更好地为我们服务,我们需定制bash shell环境. ~/.bash_profile.~/.bashrc.和~/.bash_logout 上面这三个文件是bash shell的用户环境配 ...
- [Java基础]List,Map集合总结
java.util包下: Collection |--List 接口 |----ArrayList |----LinkedList |----Vector |-----Stack |---Set ...