Data Structure Array: Maximum of all subarrays of size k
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的更多相关文章
- Data Structure Array: Maximum circular subarray sum
		
http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...
 - 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 ...
 - 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 & ...
 - 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 ...
 - Data Structure Array: Move all zeroes to end of array
		
http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...
 - 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 ...
 - 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 ...
 - Data Structure Array: Sort elements by frequency
		
http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/ #include <iostream> #include &l ...
 - 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& ...
 
随机推荐
- ios7中的edgesForExtendedLayout
			
edgesForExtendedLayout是一个类型为UIExtendedEdge的属性,指定边缘要延伸的方向. 因为iOS7鼓励全屏布局,所以它的默认值是UIRectEdgeAll——四周边缘都延 ...
 - 【优才原创】Android的拖放机制
			
优才网 [优才原创]Android的拖放机制 2016-04-18 优才学院 优才网 一.拖放机制概述 ² 拖放操作是手指触摸屏幕上的某一对象.然后拖动该对象.最后在屏幕的某个位置释放该对象并运行某种 ...
 - web开发中的路径问题
			
http://www.cnblogs.com/tianguook/archive/2012/08/31/2665755.html 转自:http://www.blogjava.net/meil/arc ...
 - Junit内部解密之四: Junit单元测试最佳实践
			
我们做使用Junit工具来做单页测试或接口测试时,需要注意一些问题,包括我们的编码规范,test规范,以及编写测试代码的策略,以下个人的总结. 1.为还没有实现的测试代码抛出一个异常.这就避免了该测试 ...
 - erlang的非平衡的二叉树的操作
			
-module(tree1). -export([test1/0]). lookup(Key,nil) -> not_found; lookup(Key,{Key,Value,_,_}) -&g ...
 - .Net中多线程类的使用和总结
			
lock, Monitor, Thread, Join, BackGroundWorker. 消费者和生产者.Async 委托Invoke TypeHandle中BlockIndex. http: ...
 - EasyUI入门视频教程
			
EasyUI入门视频教程02 http://www.tudou.com/programs/view/TBlaIcNU5ck/
 - RHEL7安装部署ZooKeeper
			
转载请注明出处:jiq•钦's technical Blog - 季义钦 文章说明: 分布式注冊中心(链接)须要安装的组件包括两个部分: 1.注冊中心服务(Zookeeper) 2.站点(Tomcat ...
 - iOS CLLocationManager定位
			
本文转载至 http://www.tuicool.com/articles/7JBRZn 在iOS8以前的版本中,我们使用CLLocationManager定位是没有问题的,最近在iOS8系统中却无法 ...
 - php之 人员的权限管理
			
1.想好权限管理的作用? 2.有什么权限内容? 3.既然有权限管理那么就会有管理员? 4.登录后每个人员的界面会是不一样的? 一.想好这个权限是什么? 就做一个就像是vip的功能,普通用户和vip用户 ...