【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 ...
随机推荐
- 【转】IE11的变化
1.navigator.userAgent中不再包含“MSIE”关键字 2.用javascript的判断是否是IE11的方法是: var isIE11 = (sUserAgent.toLowerCas ...
- 配置Nginx服务
一,安装之前准备1.nginx依赖: gcc openssl-devel pcre-devel zlib-devel 安装依赖:yum install gcc openssl-devel pcr ...
- DNS笔记 DNS区域集成到 Active Directory
可以将 DNS 区域集成到 Active Directory 中以提供增强的容错功能和安全性.OpenDNS Google Public DNS往返时间 (RTT) 远程访问服务 (RAS)域名与 ...
- jQuery编写的一款兼容IE6的图片轮播幻灯片
jQuery编写的一款兼容IE6的图片轮播幻灯片,很不错的一款jquery特效.大家可以下载下来研究研究. 每隔几秒就自动切换一波图片,此效果兼容性还做的不错,适合居多的浏览器. 适用浏览器:IE6. ...
- 在PyQt中直接使用ui文件并加载qrc资源文件
1. 用Qt设计师创建一个包含qrc资源文件的ui文件 2.打开cmd使用以下命令把qrc资源文件转换成十六进制的py文件 pyrcc4 -o C:\res.py C:\res.qrc pyrcc4 ...
- ASCII码详解
ASCII码详解 ASCII码表 ASCII码大致可以分作三部分組成.第一部分是:ASCII非打印控制字符: 第二部分是:ASCII打印字符: 第三部分是:扩展ASCII打印字符. 第一部分:ASCI ...
- How to get Financial Dimension Value from Worker Position[AX2012]
To get financial dimension value from worker position, add a new method in hcmWorker Table with scri ...
- Python学习教程(learning Python)--1.2.4 Python格式化输出科学计数
Python在浮点数据输出时,可以采用科学计数法的方式输出. 现举两个例子说明一下如何使用. eg1. 无精度要求的科学计数法浮点数据输出 >>> print(format(1234 ...
- Windows上搭建android开发环境
在搭建android开发环境时需要四部分内容,框架如下 其中Java SDK和Eclipse在java4android中有过介绍,重点介绍ADT和Android SDK的安装. 安装Android S ...
- Python 爬虫实例
下面是我写的一个简单爬虫实例 1.定义函数读取html网页的源代码 2.从源代码通过正则表达式挑选出自己需要获取的内容 3.序列中的htm依次写到d盘 #!/usr/bin/python import ...