滑动窗口(C++)
创始人
2024-11-12 16:08:05
0

样例输入

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

样例输出

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

数据范围

对于 20% 的数据,K≤N≤1000;

对于 50% 的数据,K≤N≤10^5;

对于 100% 的数据,K≤N≤10^6。

#include using namespace std;  int a[1000006];  void yjc(int n, int w) { 	deque q; 	for (int i = 0; i < n; ++i) { 		while (!q.empty() && a[q.back()] <= a[i]) { 			q.pop_back(); 		} 		q.push_back(i); 		if (i >= w - 1) { 			cout << a[q.front()] << ' '; 			if (q.front() == i - w + 1) { 				q.pop_front(); 			} 		} 	} 	cout << endl; }  void xzh(int n, int w) { 	deque q; 	for (int i = 0; i < n; ++i) { 		while (!q.empty() && a[q.back()] >= a[i]) { 			q.pop_back(); 		} 		q.push_back(i); 		if (i >= w - 1) { 			cout << a[q.front()] << ' '; 			if (q.front() == i - w + 1) { 				q.pop_front(); 			} 		} 	} 	cout << endl; }  int main() { 	int n, w; 	cin >> n >> w; 	for (int i = 0; i < n; ++i) { 		cin >> a[i]; 	}  	xzh(n, w); 	yjc(n, w);  	return 0; }

相关内容

热门资讯

此事迅速冲上热搜!aapoke... 此事迅速冲上热搜!aapoker怎么控制牌,aapoker真的假的(透视)学习教程(一贯真的有挂)-...
透视解谜!如何下载wpk透视版... 透视解谜!如何下载wpk透视版(透视)wpk透视辅助方法,教程要领(有挂技巧)-哔哩哔哩1、玩家可以...
透视窍要!wepoker透视器... 透视窍要!wepoker透视器免费,we-poker靠谱吗(脚本)了解教程(切实存在有挂)-哔哩哔哩...
一直以来!aapoker怎么拿... 一直以来!aapoker怎么拿好牌,aapoker怎么提高中牌率(透视)方针教程(好像真的是有挂)-...
透视项目!wepoker模拟器... 透视项目!wepoker模拟器哪个,wepoker有透视吗(脚本)开挂教程(一贯存在有挂)-哔哩哔哩...
透视总结!wpk透视是真的吗(... 透视总结!wpk透视是真的吗(透视)wpk透视是真的吗,教程总结(有挂解惑)-哔哩哔哩1.wpk透视...
昨日!aapoker辅助器怎么... 昨日!aapoker辅助器怎么用,aapoker怎么设置抽水(透视)技法教程(都是真的是有挂)-哔哩...
透视讲义!wepoker有透视... 透视讲义!wepoker有透视功能吗,wejoker辅助软件视频(脚本)曝光教程(竟然真的是有挂)-...
透视普及!wpk有那种辅助吗(... 透视普及!wpk有那种辅助吗(透视)wpk透视辅助方法,教程模板(今日头条)-哔哩哔哩1、完成wpk...
今天下午!aapoker免费透... 今天下午!aapoker免费透视脚本,aapoker脚本(透视)积累教程(总是是有挂)-哔哩哔哩aa...