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 < ...
随机推荐
- WMWARE下/sbin/scsi_id 返回值为空
[root@HE1 ~]# /sbin/scsi_id -g -u /dev/sdb 第一种是从VMWARE层面去解决,用文本编辑器修改vmx文件,在vmx文件中任意位置(通常在最后)添加如下行: d ...
- Goldengate双向复制配置
一.Goldengate双向复制配置 1.1.在进行如下配置之前,先在源数据库source system(原来的目标数据库)端 添加辅助的redolog配置: SQL>alter databas ...
- List与Linkedlist、Arrylist、Vector、Map应用
1.List与LinkedList List是数组链表 LinkedList是指针链表 选择List还是LinkedList要看你的使用特点. 数组链表访问快,复 ...
- Spring之循环依赖
转:http://my.oschina.net/tryUcatchUfinallyU/blog/287936 概述 如何检测循环依赖 循环依赖如何解决 Spring如何解决循环依赖 主要的几个缓存 主 ...
- ProjectManager Beta 2 项目管理器发布
上次载Alpha阶段有一个可用版本Alpha 8也在这个博客发布了,传送:http://www.cnblogs.com/deali/p/ProjectManager.html ProjectManag ...
- 安装Hadoop及Spark(Ubuntu 16.04)
安装Hadoop及Spark(Ubuntu 16.04) 安装JDK 下载jdk(以jdk-8u91-linux-x64.tar.gz为例) 新建文件夹 sudo mkdir /usr/lib/jvm ...
- iOS开发一些小技巧
1.隐藏多余的tableView的cell分割线 self.tableView.tableFooterView= [[UIViewalloc]init]; 2.取消系统自带的返回字样 [[UIBarB ...
- 【Spring】使用Spring的AbstractRoutingDataSource实现多数据源切换
最近因为项目需要在做两个项目间数据同步的需求,具体是项目1的数据通过消息队列同步到项目2中,因为这个更新操作还涉及到更新多个库的数据,所以就需要多数据源切换的操作.下面就讲讲在Spring中如何进行数 ...
- 《javascript个人理解,个人整理。》
万事开头难. 本人做前端工程师,已几年,没有特别大的,已文字方式去做总结. 前段时间,早已经想好,但是迟迟没有去下笔!好在现在陆陆续续的写下去. 我知道这是一个很大的工程,但是我还是想做下去,不为别的 ...
- 硅谷创业教父Paul Graham:如何获得创业idea
link:http://kb.cnblogs.com/page/165530/ 英文原文:How to Get Startup Ideas,翻译:Jason Zheng 要想获得创业 idea,请别试 ...