博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单调队列 hdu2823
阅读量:6202 次
发布时间:2019-06-21

本文共 1785 字,大约阅读时间需要 5 分钟。

Sliding Window
Time Limit: 12000MS   Memory Limit: 65536K
Total Submissions: 48608   Accepted: 14047
Case Time Limit: 5000MS

Description

An array of size 
n ≤ 10
6 is given to you. There is a sliding window of size 
k which is moving from the very left of the array to the very right. You can only see the 
k numbers in the window. Each time the sliding window moves rightwards by one position. Following is an example: 
The array is 
[1 3 -1 -3 5 3 6 7], and 
k is 3.
Window position Minimum value Maximum value
[1  3  -1] -3  5  3  6  7  -1 3
 1 [3  -1  -3] 5  3  6  7  -3 3
 1  3 [-1  -3  5] 3  6  7  -3 5
 1  3  -1 [-3  5  3] 6  7  -3 5
 1  3  -1  -3 [5  3  6] 7  3 6
 1  3  -1  -3  5 [3  6  7] 3 7

Your task is to determine the maximum and minimum values in the sliding window at each position. 

Input

The input consists of two lines. The first line contains two integers 
n and 
k which are the lengths of the array and the sliding window. There are 
n integers in the second line. 

Output

There are two lines in the output. The first line gives the minimum values in the window at each position, from left to right, respectively. The second line gives the maximum values. 

Sample Input

8 31 3 -1 -3 5 3 6 7

Sample Output

-1 -3 -3 -3 3 33 3 5 5 6 7
1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 7 int a[1000005],q[1000005],p[1000005],mi[1000005],ma[1000005]; 8 int n,k; 9 10 void get_min()11 {12 int i,j;13 int head=1,tail=0;14 for(i=0;i
=a[i])17 tail--;18 q[++tail]=a[i];19 p[tail]=i;20 }21 22 for(;i
=a[i])25 tail--;26 q[++tail]=a[i];27 p[tail]=i;28 while(p[head]
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4817598.html

你可能感兴趣的文章
JVM - 类加载机制(一)
查看>>
Spring单元测试
查看>>
select,iocp,epoll,kqueue及各种I/O复用机制
查看>>
Python抓取框架:Scrapy的架构
查看>>
ssh免密码登录
查看>>
特征提取与图像识别
查看>>
[RabbitMQ]08_RabbitMQ学习之exchange总结
查看>>
linux下的硬盘检测工具 Smartmontools
查看>>
Foxmail连接iRedMail邮件服务器出现mail_max_userip_connections=10 报错
查看>>
使用iRedMail开源邮件解决方案构建公司内部邮件系统
查看>>
NEW WORDS:2009-8-27
查看>>
vue 3.0 安装路由
查看>>
Java TreeMap的排序(转)
查看>>
sqlplus / as sysdba ora-01031 insufficient privileges
查看>>
Redis复制与可扩展集群搭建
查看>>
我的友情链接
查看>>
LOADING Redis is loading the dataset in memory
查看>>
ASP.Net页面刷新后自动滚动到原来位置
查看>>
java 常用正则表达式 的使用
查看>>
Struts2中request,session,application三种请求方法
查看>>