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又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串, ...
随机推荐
- SniperOJ-leak-advanced-x86-64
借助DynELF实现无libc的漏洞利用小结 1.leak-advance与leak的区别在于一个可用函数是write,一个可用函数是puts.write比puts更容易利用,虽然write需要的参数 ...
- Linux C++/C开发所必需的一系列工具
系统平台下的开发工具.开发环境各有不同.Linux C++/C开发所必需的一系列工具: 1. vi(vim)文本编辑器一个UNIX世界标准的文本编辑器,简约而强大,不论作为开发人员还是系统管理员,熟练 ...
- shell脚本,awk实现文件a的每行数据与文件b的相对应的行的值相减,得到其绝对值。
解题思路 文件 shu 是下面这样的.220 34 50 70553 556 32 211 1 14 98 33 文件 jian是下面这样的.1082 想要得到结果是下面这样的.210 24 40 6 ...
- Spring框架bean的注解管理方法之一 使用注解生成对象
首先在原有的jar包: 需Spring压缩包中的四个核心JAR包 beans .context.core 和expression 下载地址: https://pan.baidu.com/s/1qXLH ...
- iOS UIView中的坐标转换convertPoint --- iOS开发系列 ---项目中成长的知识六
如果你的UITableViewCell里面有一个Button需要响应事件,你会怎么做? 在Controller中使用 button父类的父类? 例如:UITableViewCell *parent ...
- 新浪oAuth授权
首先要拥有一个微博账号 第一步 成为新浪开发者 1.登录微博开发者界面 open.weibo.com 2. 点击登录 点击移动应用,创建应用 3.需要进行开发者认证,填写个人信息及邮箱认证,等 ...
- PAT 乙级 1012
题目 题目地址:PAT 乙级 1012 思路 最后一个测试点怎么也过不了,问题在于A2的判断,不能单纯地以0作为判断条件:假设满足A2条件的只有两个数6和6,计算结果仍然是0,但是输出A2的值是0不是 ...
- CSS 布局经典问题初步整理
CSS 定位问题 主要就是经典的绝对定位,相对定位问题. 10个文档学布局:通过十个例子讲解布局,主要涉及相对布局,绝对布局,浮动. 百度前端学院笔记 – 理解绝对定位:文章本身一般,几篇参考文献比较 ...
- 【js】【ios】【safari】【兼容问题】【转发】JS IOS/iPhone的Safari不兼容Javascript中的Date()问题
引用地址:http://www.cnblogs.com/yiven/p/6053872.html 1 var date = new Date('2016-11-11 11:11:11'); 2 d ...
- 我的Python分析成长之路9
pandas入门 统计分析是数据分析的重要组成部分,它几乎贯穿整个数据分析的流程.运用统计方法,将定量与定性结合,进行的研究活动叫做统计分析.而pandas是统计分析的重要库. 1.pandas数据结 ...