【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----全局变量和局部变量部分讲解
以此文作为自己学习的一个总结. 关于全局变量和局部变量的一句简单的定义:在函数外声明的变量都为全局变量,在函数内声明的为局部变量. 一.局部变量和全局变量重名会覆盖全局变量 var a = 1; fu ...
- arguments .length .callee caller
如果有一个函数像下面这样: function fn(){ } 那么fn这个函数下面就有一个arguments属性(你在逗我么,后面又说对象),该属性是个对象(typeof一下就知道了),然后它下面也有 ...
- php敏感词过滤
在项目开发中发现有个同事在做敏感词过滤的时候用循环在判断,其实是不用这样做的,用php的数组函数和字符串函数即可实现 function filterNGWords($string) { $badwor ...
- Ubuntu12.04卡死的解决方案
刚开始安装的时候用着还行,不过后来发现用了一会总是会出现卡死的状况 后来看了下ubuntu12.04的内核是3.2,后来把内核升级到3.5发现这种情况不会出现了. 查看内核以及升级内核 uname - ...
- ERROR 1045 (28000): Access denied for user root@localhost (using password:
错误描述: Mysql中添加用户之后可能出现登录时提示ERROR 1045 (28000): Access denied for user的错误.删除user.user中值为NULL的,或更新NULL ...
- Java字符判断
从键盘上输入一个字符串,遍历该字符串中的每个字符,若该字符为小写字母,则输出“此字符是小写字母”:若为大写字母,则输出“此字符为大写字母”:否则输出“此字符不是字母”. 代码入下: import ja ...
- Oracle并行事务回滚相关参数及视图
/******相关参数****/fast_start_parallel_rollback1.取值有3种:false,low,high2.各值含义:false ---禁用并行回滚功能 ...
- DM9000网卡的基本工作原理
MAC:主要负责数据帧的创建,数据差错,检查,传送控制等. PHY:物理接口收发器,当收到MAC过来的数据时,它会加上校验码,然后按照物理层的规则进行数据编码,再发送到传输介质上,接收过程则相反. M ...
- golang构造函数与转换函数
golang的每种类型, 凡是用type定义的类型, 其类型名既是其构造函数,也是其转换函数. 其中,构造函数后眼{...}, 转换函数后跟(...)
- python 删除list中重复元素
list = [1,1,3,4,6,3,7] 1. for s in list: if list.count(s) >1: list.remove(s) 2. list2=[] for s in ...