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又耍畸形了!!他要当飞行员,他拿到了一个飞行员测试难度序列,他设定了一个难度差的最大值,在序列中他想找到一个最长的子串, ...
随机推荐
- [LUOGU] 1364 医院设置
设有一棵二叉树,如图: [我是图] 其中,圈中的数字表示结点中居民的人口.圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接点之间的距离为1.如 ...
- TB平台搭建之二
主要想记录关于debug问题: 一般我会1.定位问题所在位置比如使能信号错误.地址读写错误.数据流pipeline错误.... 2.首先看问题的源头(对应信号)是否还正确,比如出现XX要查看她的第一级 ...
- Python多版本共存安装
Python的安装 进入Python官方网站:www.python.org下载系统对应的Python版本 按照提示步奏安装,安装路径选择自定义,方便查找 安装完成后,按win+R键,输入cmd进入cm ...
- vmalloc_init
/* linux/mm/vmalloc.c*/ struct vmap_area { unsigned long va_start; unsigned long va_end; unsigned lo ...
- Cocos2d-x学习资料集锦
Cocos2d-x学习资料集锦: 1.Cocos2d-x官方中文文档:https://github.com/chukong/cocos-docs/blob/master/catalog/zh.md 推 ...
- centos 装 android studio
一.安装前的准备 1.1.如果你还没有安装ubuntu 14.04 LTS系统,请参考下面的文章安装 http://blog.csdn.net/lsyz0021/article/details/521 ...
- 使用adb命令启查看已安装的Android应用的versionCode、versionName
列出已经安装的应用 adb shell pm list package C:\Users\CJTDEV003>adb shell pm list package package:com.sams ...
- 转:深入 AngularUI Router
原文地址:http://www.ng-newsletter.com/posts/angular-ui-router.html ui-router: https://angular-ui.github. ...
- Silverlight调用GP工具实现缓冲分析
目的: 在地图上点击一个点生成一个缓冲区. 1.制作GP工具: GP工具制作按照http://help.arcgis.com/zh-cn/arcgisdesktop/10.0/help/index.h ...
- HDU-4738 Caocao's Bridges,注意重边不是桥!
Caocao's Bridges 题意:曹操赤壁之战后卷土重来,他在n个小岛之间建立了m座桥.现在周瑜只有一颗炮弹,他只能炸毁一座桥使得这些岛屿不再连通.每座桥上都可能会有士兵把手,如果想安放***那 ...