luogu P3512 [POI2010]PIL-Pilots
题目描述
In the Byteotian Training Centre, the pilots prepare for missions requiring extraordinary precision and control.
One measure of a pilot's capability is the duration he is able to fly along a desired route without deviating too much - simply put, whether he can fly steadily. This is not an easy task, as the simulator is so sensitive that it registers even a slightest move of the yoke1.
At each moment the simulator stores a single parameter describing the yoke's position.
Before each training session a certain tolerance level
is set.
The pilots' task then is to fly as long as they can in such a way that all the yoke's position measured during the flight differ by at most
. In other words, a fragment of the flight starting at time
and ending at time
is within tolerance level
if the position measurements, starting with
-th and ending with
-th, form such a sequence
that for all elements
of this sequence, the inequality
holds.
Your task is to write a program that, given a number
and the sequence of yoke's position measurements, determines the length of the longest fragment of the flight that is within the tolerance level
.
给定n,k和一个长度为n的序列,求最长的最大值最小值相差不超过k的序列
输入输出格式
输入格式:
In the first line of the standard input two integers are given,
and
(
,
), separated by a single space, denoting the tolerance level and the number of yoke's position measurements taken.
The second line gives those measurements, separated by single spaces. Each measurement is an integer from the interval from
to
.
第一行两个有空格隔开的整数k(0<=k<=2000,000,000),n(1<=n<=3000,000),k代表设定的最大值,n代表序列的长度。第二行为n个由空格隔开的整数ai(1<=ai<=2000,000,000),表示序列。
输出格式:
Your program should print a single integer to the standard output:
the maximum length of a fragment of the flight that is within the given tolerance level.
一个整数代表最大的符合条件的序列
输入输出样例
3 9
5 1 3 5 8 6 6 9 10
4
说明
样例解释:5, 8, 6, 6 和8, 6, 6, 9都是满足条件长度为4的序列
考虑两个单调队列储存下标
每次用队列头计算答案
当两队列头差值不满足条件时,直接跳到两个最值下表最近的那个的位置
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = ;
int n,k;
int a[maxn];
int q1[maxn],q2[maxn];
int main () {
scanf("%d%d",&k,&n);
for(int i=;i<=n;i++)
scanf("%d",a+i);
q1[]=q2[]=;int be=;
int h1=,t1=,h2=,t2=;
int ans=;
for(int i=;i<=n;++i) {
while(h1<=t1&&a[q1[t1]]<a[i])t1--;
while(h2<=t2&&a[q2[t2]]>a[i])t2--;
q1[++t1]=q2[++t2]=i;
while(a[q1[h1]]-a[q2[h2]]>k) {
if(q1[h1]<q2[h2]) be=q1[h1]+,h1++;
else be=q2[h2]+,h2++;
}
ans=max(ans,i-be+);
}
printf("%d\n",ans);
return ;
}
luogu P3512 [POI2010]PIL-Pilots的更多相关文章
- P3512 [POI2010]PIL-Pilots
P3512 [POI2010]PIL-Pilots我一开始打的O(n^2)(最坏情况)的算法.枚举区间长度.60分 #include<iostream> #include<cstdi ...
- P3512 [POI2010]PIL-Pilots-洛谷luogu
刚研究完单调队列和单调栈 于是就找题做了 发现了这道蓝题 以为很简单 就着手来写了 然而 并不是我想的那样 只是有一点点思路 无奈 还是看了题解 好吧题解是真的挺好的 ---------------- ...
- Luogu P3496 [POI2010]GIL-Guilds(贪心+搜索)
P3496 [POI2010]GIL-Guilds 题意 给一张无向图,要求你用黑(\(K\))白(\(S\))灰(\(N\))给点染色,且满足对于任意一个黑点,至少有一个白点和他相邻:对于任意一个白 ...
- [洛谷P3512 [POI2010]PIL-Pilots]
题目链接: 传送门走这里 题目分析: 感觉不是很难啊--不像是蓝题(AC量也不像)恶意评分? 少打了一个+1调了半天,就这样居然还能过60pts?我思路和题解第一篇高度重合是什么鬼啊,太过分了吧本来还 ...
- BZOJ 2085 luogu P3502 [POI2010]Hamsters (KMP、Floyd、倍增)
数组开小毁一生-- 题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2085 这题在洛谷上有个条件是"互不包含",其实 ...
- Luogu P3511 [POI2010]MOS-Bridges
题目 二分答案然后混合图欧拉回路,因为没有SPJ所以就没写了,怕写了有锅.
- BZOJ 2096: [Poi2010]Pilots( set )
用个set维护就可以水过去...O(NlogN) 应该可以用单调队列O(N).... --------------------------------------------------------- ...
- bzoj2096[Poi2010]Pilots 单调队列
2096: [Poi2010]Pilots Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 983 Solved: 513[Submit][Statu ...
- 【BZOJ2096】[Poi2010]Pilots 双指针+单调队列
[BZOJ2096][Poi2010]Pilots Description Tz又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串, ...
随机推荐
- graphviz layer 教程(非布局)
官方 pdf 上讲解的很少,没有图片. http://www.graphviz.org/wiki/how-use-drawing-layers-overlays 这里有图片,但是又没有说如何生成. 直 ...
- javaEE(10)_jdbc基本使用
一.JDBC简介 1.SUN公司为了简化.统一对数据库的操作,定义了一套Java操作数据库的规范,称之为JDBC,JDBC(Java Data Base Connectivity,java数据库连接) ...
- getComputedStyle与currentStyle获取元素当前的css样式
CSS的样式分为三类: 内嵌样式:是写在标签里面的,内嵌样式只对所在的标签有效内部样式:是写在HTML里面的,内部样式只对所在的网页有效外部样式表:如果很多网页需要用到同样的样式,将样式写在一个以.c ...
- perl 对ENV环境变量的使用
1.hash 方式访问. %ENV key为环境变量名,value为环境变量值 2.调用ENV模块 . use Env qw(PATH); print "path is $ENV{path ...
- nw335 debian sid x86-64 -- 2 驱动的方式
1 linux内核自带 2 realtek 提供的官方驱动 3 使用xp的驱动 4 第三方驱动(现在成功的,最好的方式)
- js/jquery判断浏览器 & 停止加载
JS获取浏览器信息 复制代码代码如下: 浏览器代码名称:navigator.appCodeName浏览器名称:navigator.appName浏览器版本号:navigator.appVersion对 ...
- java excutors 四种类型的线程
http://blog.csdn.net/ochangwen/article/details/53044733
- 关于面试总结-app测试面试题
前言 现在面试个测试岗位,都是要求全能的,web.接口.app啥都要会测,那么APP测试一般需要哪些技能呢? 面试app测试岗位会被问到哪些问题,怎样让面试管觉得你对APP测试很精通的样子? 本篇总结 ...
- 【PL/SQL编程基础】
[PL/SQL编程基础]语法: declare 声明部分,例如定义变量.常量.游标 begin 程序编写,SQL语句 exception 处理异常 end: / 正斜杠表示执行程序快范例 -- Cre ...
- POJ 2643 Election
Election Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3558 Accepted: 1692 Descript ...