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. Java Learning Path(五)资源篇

    Java Learning Path(五)资源篇 1. http://java.sun.com/ (英文) Sun的Java网站,是一个应该经常去看的地方.不用多说. 2.http://www-900 ...

  2. Ubuntu 下修改 Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

    在Ubuntu上安装Apache,每次重启,都会出现以下错误提示: Could not reliably determine the server’s fully qualified domain n ...

  3. 在服务端发起一个Post请求

    1.http://www.tuling123.com/openapi/api?key=9d2ff29d44b54e55acadbf5643569584&info=? 上面这个请求在服务端发起 ...

  4. C# 指南之装箱与拆箱

    基础 1.值类型 1.1 在栈上分配内存,在声明时初始化才能使用,不能为null. 1.2 值类型超出作用范围系统自动释放内存. 1.3 主要由两类组成:结构,枚举 结构分为以下几类 1.整形(Sby ...

  5. PrincetonUniversity-Coursera 算法:算法简单介绍

    Course Overview What is this course? Intermediate-level survey course. Programming and proble solvin ...

  6. vim 命令行使用技巧

    1. <Ctrl-U> <Ctrl-K> 删除光标到开头的输入 2. <Ctrl-W> 删除最近输入的单词 3. <Ctrl-H> 删除光标之前的一个字 ...

  7. list集合转换成json类型

    public String gettext(HttpServletRequest request,HttpServletResponse response){ List<xuanhuan_> ...

  8. ACM算法整理(不断补充ing)

    动态规划 1.背包问题 (1)01背包 ,n) DFR(v,V,C[i]) F[v]=max(F[v],F[v-C[i]]+W[i]); } //初始化时 //若背包不一定装满F全初始化为0 //若装 ...

  9. MapReduce小文件处理之CombineFileInputFormat实现

    在MapReduce使用过程中.一般会遇到输入文件特别小(几百KB.几十MB).而Hadoop默认会为每一个文件向yarn申请一个container启动map,container的启动关闭是很耗时的. ...

  10. HTML_<a>

    1.在a标签中调用js函数最适当的方法推荐使用: (1) a href="javascript:void(0);" onclick="js_method()" ...