优先队列~~~

E - 楼上哪里比楼上的楼上简单了?没看出来!但是我知道我最简单了!
Time Limit:12000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 positionMinimum valueMaximum value
[1  3  -1] -3  5  3  6  7 -13
 1 [3  -1  -3] 5  3  6  7 -33
 1  3 [-1  -3  5] 3  6  7 -35
 1  3  -1 [-3  5  3] 6  7 -35
 1  3  -1  -3 [5  3  6] 7 36
 1  3  -1  -3  5 [3  6  7]37

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 3
1 3 -1 -3 5 3 6 7

Sample Output

-1 -3 -3 -3 3 3
3 3 5 5 6 7

这个题数据量异常庞大 dp基本没戏 那么只能考虑二分或者优先队列这种比较快捷的方法 本弱只会这两种简化方式 如果有大神还有更好的解决方法 求告知 求抽脸Orz....

这个题 还是用优先队列吧~~~~

#include<cstdio>
using namespace std;
int tot,win;
int a[1000006],q[1000006];
void getmin(){
    int tail=0,head=1;
    for(int i=1;i<=tot;i++){
        while(head<=tail&&a[q[tail]]>=a[i]) tail--;
        q[++tail]=i;
        if(i>=win){
            while(q[head]<i-win+1) head++;//out of time?
            printf("%d ",a[q[head]]);
        }
    }
    printf("\n");
}
void getmax(){
    int tail=0,head=1;
    for(int i=1;i<=tot;i++){
        while(head<=tail&&a[q[tail]]<=a[i]) tail--;
        q[++tail]=i;
        if(i>=win){
            while(q[head]<i-win+1) head++;//out of time?
            printf("%d ",a[q[head]]);
        }
    }
    printf("\n");
}
int main(){
    scanf("%d%d",&tot,&win);
    for(int i=1;i<=tot;i++) scanf("%d",&a[i]);
    getmin();getmax();
    return 0;
}

需要注意的是 这里的a是真实的数字 而q则是在这里检查是否当玻璃发生移动的时候 返回出需要值的位置 这里的取大和取小实质上都是一种操作,是通过q数组来调节位置的 so....你肯定懂了~~~

最后 要是有大神想出更好的解决方法 请告诉我 跪求打脸QAQ



1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值