●BZOJ 3831 [Poi2014]Little Bird
题链:
#include<cstdio>
#include<cstring>
#include<iostream>
#define MAXN 1000500
using namespace std;
int H[MAXN],F[MAXN];
int N,Q;
void read(int &x){
static int f; static char ch;
x=0; f=1; ch=getchar();
while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
x=x*f;
}
bool off(int x,int y){
if(H[y]>=H[x]){
if(F[y]<=F[x]) return 1;
else return 0;
}
else{
if(F[y]<F[x]) return 1;
else return 0;
}
}
int main(){
static int pos[MAXN],l,r;
read(N);
for(int i=1;i<=N;i++) read(H[i]);
read(Q);
for(int q=1,k;q<=Q;q++){
read(k); l=1; r=0;
F[1]=0; pos[++r]=1;
for(int i=2;i<=N;i++){
while(l<=r&&i-pos[l]>k) l++;
F[i]=F[pos[l]]+(H[pos[l]]<=H[i]);
while(l<=r&&off(pos[r],i)) r--;
pos[++r]=i;
}
printf("%d\n",F[N]);
}
return 0;
}
●BZOJ 3831 [Poi2014]Little Bird的更多相关文章
- Bzoj 3831 [Poi2014]Little Bird
3831: [Poi2014]Little Bird Time Limit: 20 Sec Memory Limit: 128 MB Submit: 310 Solved: 186 [Submit][ ...
- BZOJ 3831: [Poi2014]Little Bird【动态规划】
Description In the Byteotian Line Forest there are trees in a row. On top of the first one, there ...
- 单调队列应用--BZOJ 3831 Little Bird
3831: [Poi2014]Little Bird Time Limit: 20 Sec Memory Limit: 128 MB Description In the Byteotian Lin ...
- BZOJ 3831
3831: [Poi2014]Little Bird Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 121 Solved: 68[Submit][S ...
- bzoj3831 [Poi2014]Little Bird 单调队列优化dp
3831: [Poi2014]Little Bird Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 505 Solved: 322[Submit][ ...
- 单调队列优化DP || [Poi2014]Little Bird || BZOJ 3831 || Luogu P3572
题面:[POI2014]PTA-Little Bird 题解: N<=1e6 Q<=25F[i]表示到达第i棵树时需要消耗的最小体力值F[i]=min(F[i],F[j]+(D[j]> ...
- 【刷题】BZOJ 4543 [POI2014]Hotel加强版
Description 同OJ3522 数据范围:n<=100000 Solution dp的设计见[刷题]BZOJ 3522 [Poi2014]Hotel 然后发现dp的第二维与深度有关,于是 ...
- P3572 [POI2014]PTA-Little Bird
P3572 [POI2014]PTA-Little Bird 一只鸟从1跳到n.从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制k,求每次最少耗费多少体力 很简短的题目哼. ...
- 【BZOJ3831】[Poi2014]Little Bird 单调队列
[BZOJ3831][Poi2014]Little Bird Description In the Byteotian Line Forest there are trees in a row. ...
随机推荐
- 《Language Implementation Patterns》之 数据聚合符号表
本章学习一种新的作用域,叫做数据聚合作用域(data aggregate scope),和其他作用域一样包含符号,并在scope tree里面占据一个位置. 区别在于:作用域之外的代码能够通过一种特殊 ...
- Python 单向循环链表
操作 is_empty() 判断链表是否为空 length() 返回链表的长度 travel() 遍历 add(item) 在头部添加一个节点 append(item) 在尾部添加一个节点 inser ...
- .NET Core装饰模式和.NET Core的Stream
该文章综合了几本书的内容. 某咖啡店项目的解决方案 某咖啡店供应咖啡, 客户买咖啡的时候可以添加若干调味料, 最后要求算出总价钱. Beverage是所有咖啡饮料的抽象类, 里面的cost方法是抽象的 ...
- Filter 和 interceptor 的区别
1. 拦截器 interceptor ● 特点:interceptor 依赖于web框架,在Spring<MV中就是依赖于springMVC框架.在实现上是基于Java的反射机制,属于面向切面编 ...
- 码农、黑客和2B程序员之间的区别
码农: 黑客: 2B程序员: 求2的32次方: 码农: System.out.println(Math.pow(2, 32)); 黑客: System.out.println(1L<<32 ...
- redis 持久化之 RDB
redis的运维过程中,我们对数据持久化做一个基本的总结. 1什么是持久化: redis 所有数据保持在内存中,对数据的更新将异步地保存到磁盘上. RDB 文件创建的过程是直接从内存 写入到我们我磁盘 ...
- js判断语句关于true和false后面跟数字或字符串的问题
我经常在代码中看到很长串判断,看到就头疼,简单的整理一下. 比如:(client.top>=0&&client.left>=0&&client.bottom ...
- java基础总结(1)安装jdk
卸载java java -version yum remove java yum groupjava java 安装java tar -zxvf jdk-8u60-linu ...
- DevExpress控件的一些快捷操作
用的DevExpress控件时,有一些操作并不太方便,根据我自己需要的封装了一些控件的事件,调用的时候直接绑定控件的事件就可以了 例如: this.ComboBoxEdit.KeyDown += Ct ...
- ASP.NET CORE系列【二】使用Entity Framework Core进行增删改查
介绍 EntityFrameworkCore EF core 是一个轻量级的,可扩展的EF的跨平台版本.对于EF而言 EF core 包含许多提升和新特性,同时 EF core 是一个全新的代码库,并 ...