日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 2823 Sliding Window

發(fā)布時間:2024/6/30 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 2823 Sliding Window 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Sliding Window 鏈接:http://poj.org/problem?id=2823
Time Limit:?12000MS?Memory Limit:?65536K
???
Case Time Limit:?5000MS

Description

An array of size?n?≤ 106?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

Source

POJ Monthly--2006.04.28, Ikki 題意:給定一個數(shù)列,從左至右輸出每個長度為m的數(shù)列段內(nèi)的最小數(shù)和最大數(shù)。
數(shù)列長度:N<=106m<=N #include<iostream> #include<cstdio> using namespace std;const int N = 1000005;int n,k,m,mn[N],mx[N],n1,n2;struct node{int id, data; };node dj[N],dz[N];//dz 遞增隊列 dj 遞減隊列 int main() {cin >> n >> k;int headj = 1,tail1 = 0,headz = 1,tail2 = 0;for(int i = 1; i <= n; i++){scanf("%d",&m);while(m <= dj[tail1].data && tail1 >= headj) tail1 --;//保持單調(diào)性 while(m >= dz[tail2].data && tail2 >= headz) tail2 --;dj[++tail1].data = m;dj[tail1].id = i;dz[++tail2].data = m;dz[tail2].id = i;if(i >= k){//開始記錄第n段中的最值 if(dj[headj].id <= i-k) mn[++n1] = dj[++headj].data;//過期了 else mn[++n1] = dj[headj].data;if(dz[headz].id <= i-k) mx[++n2] = dz[++headz].data;else mx[++n2] = dz[headz].data;}}for(int i = 1; i <= n1; i++)printf("%d ",mn[i]);cout<<endl;for(int i = 1; i <= n1; i++)printf("%d ",mx[i]);return 0; }

第一次手打隊列,以后還是用雙向吧

轉(zhuǎn)載于:https://www.cnblogs.com/EdSheeran/p/8406551.html

總結(jié)

以上是生活随笔為你收集整理的POJ 2823 Sliding Window的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。