3404: [Usaco2009 Open]Cow Digit Game又见数字游戏
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏
Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 72 Solved: 48
[Submit][Status][Discuss]
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
题解:很萌的博弈论问题。。。但是我还是在读题上逗比了N次——第一次我以为每次可以减去 1-最大的位数 ;第二次我以为可以减去 最小的位数-最大的位数 ;直到第三次才发现只可以减去最大位数和最小位数。。。别的没了,博弈论经典算法AC之
PS:不过虽然AC了,但是2800ms+,时限为3s,这个速度比较滚粗,于是本人打算明天再来一发优化题解么么哒!!!
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n,t:longint;
a:array[..,..] of boolean;
b:array[..,..] of longint;
function max(x,y:longint):longint;
begin
if x>y then max:=x else max:=y;
end;
function min(x,y:longint):longint;
begin
if x<y then min:=x else min:=y;
end;
begin
a[,]:=false;a[,]:=true;
for i:= to do
begin
j:=i;k:=;t:=;
while j> do
begin
k:=max(k,j mod );
if (j mod )> then t:=min(t,j mod );
j:=j div ;
end;
a[i,]:=false;
if a[i-t,] then a[i,]:=true;
if a[i-k,] then a[i,]:=true;
a[i,]:=true;
if not(a[i-t,]) then a[i,]:=false;
if not(a[i-k,]) then a[i,]:=false;
end;
readln(n);
for i:= to n do
begin
readln(m);
if a[m,] then writeln('YES') else writeln('NO');
end;
readln;
end.
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏的更多相关文章
- 【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 写挫好几次.... 裸的博弈论即可.. #include <cstdio> #in ...
- BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
一开始被题意坑了= =,题目是说这个数字的最大和最小,不是个位的最大和最小= = 不知道怎么做只能递推了,必胜态就是存在能到达必败态的,必败态就是只能到达必胜态的 CODE: #include< ...
- 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】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
[算法]贪心&&堆 [题解]反过来看就是合并任意两块木板,花费为木板长度之和. 显然从最小的两块开始合并即可,用堆(优先队列)维护. 经典DP问题石子归并是只能合并相邻两堆石子,所以不 ...
- bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶 ...
- 【BZOJ】1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏(刷水严重)
http://www.lydsy.com/JudgeOnline/problem.php?id=1666 这种我就不说了.. #include <cstdio> #include < ...
随机推荐
- No curses/termcap library found
CentOS6.5中编译Mysql时遇见如下错误 error: No curses/termcap library found checking for tgetent in -lncurses... ...
- Eclipse插件手动安装
拷贝至eclipse安装目录/dropins/文件夹下面: 不建议直接拷贝到features/ 和plugins/ 里面:
- Flex组件的生命周期
组件实例化生命周期描述了用组件类创建组件对象时所发生的一系列步骤,作为生命周期的一部分,flex自动调用组件的的方法,发出事件,并使组件可见. 下面例子用as创建一个btn控件,并将其加入容器中 va ...
- redis内存占用说明
执行info命令后,找到Memory这一栏,就可以看到内存的使用信息了,如下图: # Memory used_memory:13490096 //数据占用了多少内存(字节) used_memory_h ...
- (一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10)
(一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10) 系统要求 64位 Windows 10 除了家庭版的 都支持 ~ 64位CPU CPU至少是四核心以上~ 至少 ...
- 与中国最顶尖sharepoint工程师共舞
最近又跳了,来到某家外企.自以为善能称心如意,谁知乃井里之蛙. 给我的最大感触是,做sharepoint一定要做过非常大型的部署开发,没有经过这种淬炼,天天闷声研究,做一些页面功能,对技术提升毫无帮助 ...
- Windows Azure Virtual Machine (34) 保护Azure虚拟机
<Windows Azure Platform 系列文章目录> 请注意:我们在Azure上创建的虚拟机,都是可以通过公网IP地址来访问的.(直接通过虚拟机的IP地址:PIP,或者通过负载均 ...
- 通过spring实现javamail发送邮件功能
以前很早的时候大家都用javamail实现发送邮件的功能,而且我们也一直沿用至今,代码拷过来用用就行了,现在我们改为用spring来实现,这样一来减少代码的复杂度,也能更好的契合spring理念 首先 ...
- [转载]【虚拟化系列】VMware vSphere 5.1 简介与安装
转载自:http://mabofeng.blog.51cto.com/2661587/1017680 一. VMware vSphere 5.1简介 vSphere是VMware推 ...
- MongoDB基础之六 索引
一 . 索引概述和基本操作 1. 索引提高查询速度,降低写入速度,权衡常用的查询字段,不必在太多列上建索引2. 在mongodb中,索引可以按字段升序/降序来创建,便于排序3. 默认是用btree来组 ...