【BZOJ】【3831】【POI2014】Little Bird
DP/单调队列优化
水题水题水题水题
单调队列优化的线性dp……
WA了8次QAQ,就因为我写队列是[l,r),但是实际操作取队尾元素的时候忘记了……不怎么从队尾取元素嘛……平时都是直接往进放的……还是得记住这个双端队列的错点啊!!
//BZOJ 3831
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
const int N=,INF=~0u>>;
//#define debug
int n,m,a[N],f[N],q[N]; int main(){
#ifndef ONLINE_JUDGE
freopen("file.in","r",stdin);
#endif
scanf("%d",&n);
F(i,,n) scanf("%d",&a[i]); scanf("%d",&m);
while(m--){
int l=,r=,k=;
memset(q,,sizeof q); scanf("%d",&k);
f[]=f[]=;
q[r++]=;
F(i,,n){
while(q[l]+k<i && l<r) l++;
f[i]=f[q[l]] + ((a[q[l]]<=a[i]) ? : ) ;
while( ((f[i]<f[q[r-]]) || (f[i]==f[q[r-]] && a[i]>=a[q[r-]])) && l<r) r--;
q[r++]=i;
}
printf("%d\n",f[n]);
}
return ;
}
3831: [Poi2014]Little Bird
Time Limit: 20 Sec Memory Limit: 128 MB
Submit: 191 Solved: 114
[Submit][Status][Discuss]
Description
the Byteotian Line Forest there are trees in a row. On top of the
first one, there is a little bird who would like to fly over to the top
of the last tree. Being in fact very little, the bird might lack the
strength to fly there without any stop. If the bird is sitting on top of
the tree no. , then in a single flight leg it can fly to any of the
trees no.i+1,i+2…I+K, and then has to rest afterward.
tiresome if it ends in a tree at least as high as the one where is
started. Otherwise the flight leg is not tiresome.
so that the overall flight is least tiresome, i.e., it has the minimum
number of tiresome legs. We note that birds are social creatures, and
our bird has a few bird-friends who would also like to get from the
first tree to the last one. The stamina of all the birds varies, so the
bird's friends may have different values of the parameter . Help all
the birds, little and big!
Input
integer N(2<=N<=1 000 000) in the first line of the standard
input: the number of trees in the Byteotian Line Forest. The second line
of input holds integers D1,D2…Dn(1<=Di<=10^9) separated by
single spaces: Di is the height of the i-th tree.
Q(1<=Q<=25): the number of birds whose flights need to be planned.
The following Q lines describe these birds: in the i-th of these lines,
there is an integer Ki(1<=Ki<=N-1) specifying the i-th bird's
stamina. In other words, the maximum number of trees that the i-th bird
can pass before it has to rest is Ki-1.
Output
should print exactly Q lines to the standard output. In the I-th line,
it should specify the minimum number of tiresome flight legs of the i-th
bird.
Sample Input
4 6 3 6 3 7 2 6 5
2
2
5
Sample Output
1
HINT
Source
【BZOJ】【3831】【POI2014】Little Bird的更多相关文章
- 【BZOJ 2754 喵星球上的点名】
Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2512 Solved: 1092[Submit][Status][Discuss] Descript ...
- 【BZOJ】3052: [wc2013]糖果公园
http://www.lydsy.com/JudgeOnline/problem.php?id=3052 题意:n个带颜色的点(m种),q次询问,每次询问x到y的路径上sum{w[次数]*v[颜色]} ...
- 【BZOJ】3319: 黑白树
http://www.lydsy.com/JudgeOnline/problem.php?id=3319 题意:给一棵n节点的树(n<=1e6),m个操作(m<=1e6),每次操作有两种: ...
- 【BZOJ】3319: 黑白树(并查集+特殊的技巧/-树链剖分+线段树)
http://www.lydsy.com/JudgeOnline/problem.php?id=3319 以为是模板题就复习了下hld............................. 然后n ...
- 【BZOJ】【1025】【SCOI2009】游戏
DP/整数拆分 整个映射关系可以分解成几个循环(置换群的预备知识?),那么总行数就等于各个循环长度的最小公倍数+1(因为有个第一行的1~N).那么有多少种可能的排数就等于问有多少种可能的最小公倍数. ...
- 【BZOJ】1013: [JSOI2008]球形空间产生器sphere
[BZOJ]1013: [JSOI2008]球形空间产生器sphere 题意:给n+1个n维的点的坐标,要你求出一个到这n+1个点距离相等的点的坐标: 思路:高斯消元即第i个点和第i+1个点处理出一个 ...
- 【BZOJ】1002:轮状病毒(基尔霍夫矩阵【附公式推导】或打表)
Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道.如下图 ...
- 【BZOJ】【3697】采药人的路径&【3127】【USACO2013 Open】Yin and Yang
点分治 Orz hzwer 倒是比较好想到点分治……然而在方案统计这里,我犯了两个错误…… 1.我比较傻逼的想的是:通过儿子来更新父亲,也就是统计以x为根的子树中xxxx的路径有多少条……这样转移. ...
- 【BZOJ】【3083】遥远的国度
树链剖分/dfs序 其实过了[BZOJ][4034][HAOI2015]T2以后就好搞了…… 链修改+子树查询+换根 其实静态树的换根直接树链剖分就可以搞了…… 因为其实只有一样变了:子树 如果roo ...
- 【BZOJ】【2434】【NOI2011】阿狸的打字机
AC自动机+DFS序+BIT 好题啊……orz PoPoQQQ 大爷 一道相似的题目:[BZOJ][3172][TJOI2013]单词 那道题也是在fail树上数有多少个点,只不过这题是在x的fail ...
随机推荐
- JS中的控制函数调用:call(),apply()和bind()
所有的函数都具有call(),apply()和bind()方法.它们可以在执行方法的时候用一个值指向this,并改变面向对象的作用域. apply方法: 以下的两种表达式是等价的: func(arg1 ...
- PHP Startup: Unable to load dynamic library
昨天帮一朋友配置服务器结果发现apache日志中有PHP Warning: PHP Startup: Unable to load dynamic library 提示了,然后调试数据库连接发现提示C ...
- php生成随机字符串和验证码的类
网上有很多的php随机数与验证码的代码与文章,真正适用的没有几个. 索性自己搞一个吧. 开始本节的php教程 吧,以下代码的实现,主要做到可以很好区分一个get_code(),另一个create_ch ...
- eclipse使用快捷键
注意热键冲突 内容补全键 Alt+/ 快速修复键 ctrl+1 代码移动 Alt+上下键(选中代码块) 左右移动 tab(右边)Shift+tab( ...
- STM32F0xx_PWR低功耗配置详细过程
Ⅰ.概述 今天总结PWR部分知识,请看“STM32F0x128参考手册V8”第六章.提供的软件工程是关于电源管理中的停机模式,工程比较常见,但也是比较简单的一个实例,根据项目的不同还需要适当修改或者添 ...
- Stream,Reader/Writer,Buffered的区别(2)
Reader: Reader的子类: 1.BufferedReader: FileReader 没有提供读取文本行的功能,BufferedReader能够指定缓冲区大小,包装了read方法高效读取字符 ...
- Python: 迭代器与生成器小结
迭代器与生成器的区别: 1. 迭代器由Class对象创建. 生成器由包含yield表达的Function对象或者Generator Expression创建. 2. 迭代器的原理: (1)由Itera ...
- golang的++与--
http://godoc.golangtc.com/doc/faq#inc_dec 简单地说, 在golang中++,--操作是语句而不是表达式. 所以a=b++, return x++之类绝对提示错 ...
- linux eclipse
方法一: 此外,众所周知,Eclipse是Java程序,因此很容易就实现了跨平台,也是众所周知,Java的大型程序非常吃内存,即使有512MB内存, 仍然感觉Eclipse的启动速度很慢.个人认为1G ...
- 为什么学习Python
因为做iOS开发的,之前一直用OC,但是突然有一天苹果说出Swift,但是那时候的Swift真的是Bug多多,语法都不固定,所以只是大致看了看,而一年多之后,Swift已经发布2.0了,语言也相对稳定 ...