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. 改变datagrid中指定单元格的值

    //自己设置编辑时显示的内容 $('#purchasegroupname'+index).html(name); //单元格真实内容 $('#material_datagrid').datagrid( ...

  2. ASP.NET综合管理ERP系统100%源代码+所有开发文档

    该系统开发环境为:VS2010,数据库採用SQL Server,框架为ASP.NET. 源代码包含所有文档说明,代码简单易懂,凝视完整. 提示:假设没有安装水晶报表系统执行会报错,报表安装程序已经打包 ...

  3. jenkins构建java项目找不到命令mvn,java的解决方法

    jenkins构建java项目时出现的报错情况: $ mvn clean install FATAL: command execution failed java.io.IOException: er ...

  4. UIView的endEditing:方法

    当视图收到endEditing:消息时,如果视图(或者其下的人和子视图)是当前的第一响应对象,就会取消自己的第一响应对象状态, 而且虚拟键盘也会消失(传入的参数代表是否需要强制取消第一响应对象状态.有 ...

  5. JSON Web Token (JWT) 实现与使用方法

    1. JSON Web Token是什么 JSON Web Token (JWT)是一个开放标准(RFC 7519),它定义了一种紧凑的.自包含的方式,用于作为JSON对象在各方之间安全地传输信息.该 ...

  6. TCP是如何保证包的顺序传输

    转自:http://blog.csdn.net/ggxxkkll/article/details/7894112 大家都知道,TCP提供了最可靠的数据传输,它给发送的每个数据包做顺序化(这看起来非常烦 ...

  7. android studio改动module名称

    新建一个android studio项目,默认Module名称是app 右键app选择Rename,或者Shift + F6也能够.重命名module名称 重命名为abc之后中,如图上面箭头所指的ap ...

  8. vi编辑器命令大全

    >> from zhuhaiqing.info

  9. PriorityBlockingQueue优先队列的二叉堆实现

    转载请注明原创地址http://www.cnblogs.com/dongxiao-yang/p/6293807.html java.util.concurrent.PriorityBlockingQu ...

  10. 简洁方便的集合处理——Java 8 stream流

    背景 java 8已经发行好几年了,前段时间java 12也已经问世,但平时的工作中,很多项目的环境还停留在java1.7中.而且java8的很多新特性都是革命性的,比如各种集合的优化.lambda表 ...