http://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; void printKMax(int arr[], int n, int k) {
deque<int> S;
S.push_back();
for (int i = ; i < k; i++) {
while (!S.empty() && arr[i] >= arr[S.back()]) S.pop_back();
S.push_back(i);
}
for (int i = k; i < n; i++) {
cout << arr[S.front()] << " ";
while (!S.empty() && i - k >= S.front()) S.pop_front();
while (!S.empty() && arr[S.back()] <= arr[i]) S.pop_back();
S.push_back(i);
}
cout << arr[S.front()] << endl;
} int main() {
int arr[] = {, , , , , , };
printKMax(arr, , );
return ;
}

Data Structure Array: Maximum of all subarrays of size k的更多相关文章

  1. Data Structure Array: Maximum circular subarray sum

    http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...

  2. Data Structure Array: Maximum sum such that no two elements are adjacent

    http://www.geeksforgeeks.org/maximum-sum-such-that-no-two-elements-are-adjacent/ #include <iostre ...

  3. Data Structure Array: Given an array arr[], find the maximum j – i such that arr[j] > arr[i]

    http://www.geeksforgeeks.org/given-an-array-arr-find-the-maximum-j-i-such-that-arrj-arri/ #include & ...

  4. Data Structure Array: Find the Missing Number

    http://www.geeksforgeeks.org/find-the-missing-number/ 1. use sum formula, O(n), O(1) 2. use XOR, O(n ...

  5. Data Structure Array: Move all zeroes to end of array

    http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...

  6. Data Structure Array: Find if there is a subarray with 0 sum

    http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ #include <iostream> #incl ...

  7. Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times

    http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-tha ...

  8. Data Structure Array: Sort elements by frequency

    http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/ #include <iostream> #include &l ...

  9. Data Structure Array: Largest subarray with equal number of 0s and 1s

    http://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s/ #include <iostream& ...

随机推荐

  1. iOS仿支付宝首页的刷新布局效果

    代码地址如下:http://www.demodashi.com/demo/12753.html XYAlipayRefreshDemo 运行效果 动画效果分析 1.UI需要变动,向上滑动的时候,顶部部 ...

  2. Android 应用程序分析

    从这点上看,android应用程序实际上是由多个Activity按照一定的次序拼装起来的, 只不过拼装的过程中,后台传递了一些数据,使得各个Activity之间能比较好的衔接起来.     在 and ...

  3. zxing学习笔记 android入门

    对于刚开始学习android开发的童鞋们来说,若有一个简单而又全面的android工程能来剖析,那就是再好不过了,zxing就是不错得例子.    zxing的源码可以到google code上下载, ...

  4. ASP.NET常见命名空间及其功能描述

    命名空间 |  功能描述 System |  包含CLR的基本类型和基类,定义了常用的值类型和引用类型,事件.接口.属性和异常处理等 System.Text | 包含用于文本处理的类,实现了不同编码方 ...

  5. ASP.NET CORE RAZOR :初始化数据库

    官方说法是:设定数据库种子https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/razor-pages/sql 应用背景:初次部署系统时,设定一 ...

  6. SpringMVC 学习笔记(十一) SpirngMVC执行流程

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTY3NDc0NTA2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

  7. karma + phantom + mocha + sion + chai + nightwatch + selenium2(webdriver) 测试框架学习

    第三方的教程传送门 https://segmentfault.com/a/1190000004558796 karma # github https://github.com/karma-runner ...

  8. iOS中三种方式实现登录界面播放视频或gif效果

    现在app都做的越来越炫酷,各种动画效果,各种特效很好的提高了用户的体验.很多app在登录界面都使用了动画效果,比如Uber,Keep,QQ等等.这些动画效果基本都是使用gif或者MP4来实现的. 效 ...

  9. windows 10右键项添加Notepad++

    1.打开注册表编辑器,开始->运行->regedit. 2.在HKEY_CLASSSES_ROOT→ * → Shell 下,在Shell下,新建项命名为Open With Notepad ...

  10. wps文档怎样去除广告

    安装完 WPS 之后右键—属性—打开文件夹位置(如图) 接下来进入 10.1.0.6929 文件夹内,再次进入 office6 文件夹内,找到 wpscenter 应用程序,将其删除.此应用包含定时弹 ...