题意:给出一个序列,求出每连续k个数字中最大的数和最小的数. 这是道单调队列裸题,直接写就行了. 本来用deque写出来后,发现在poj上硬是超时了,在discuss上看很多人也在抱怨超时的问题,据说在uestc上也有这题,我过去提交终于过了... 但是poj还是没有过,于是我用数组模拟队列来写,提交还是超时,折腾了一会,把g++改成c++终于5s多过了... 注意如果是直接输出答案的话,如果k=1可能会出错. 代码: #include <cstdio> #include <cstrin…
一.概念介绍 1. 双端队列 双端队列是一种线性表,是一种特殊的队列,遵守先进先出的原则.双端队列支持以下4种操作: (1)   从队首删除 (2)   从队尾删除 (3)   从队尾插入 (4)   查询线性表中任意一元素的值 2. 单调队列 单调队列是一种特殊的双端队列,其内部元素具有单调性.最大队列与最小队列是两种比较常用的单调队列,其内部元素分别是严格单调递减(不是非递增)和严格单调递增(不是非递减)的. 单调队列的常用操作如下: (1) 插入:若新元素从队尾插入后会破坏单调性,则删除队…
/***************************************************************** 题目: Sliding Window(poj 2823) 链接: http://poj.org/problem?id=2823 题意: 给一个数列,找所有连续k个数的最小值和最大值. 算法: 单调队列(入门) *******************************************************************/ #include<…
Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 48930   Accepted: 14130 Case Time Limit: 5000MS Description An array of size n ≤ 106 is given to you. There is a sliding window of size k which is moving from the very left…
单调队列 加了读入挂比不加更慢.... 而且这份代码要交c++ 有大神G++跑了700ms..... orzorzorz #include<iostream> #include<cstdio> using namespace std; int a[1000086]; int num[1000086]; int fi,la; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n…
单调队列,我用deque维护.这道题不难写,我第二次写单调队列,1次AC. ----------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<deque> #define rep(i,r) for(int i=0;i<r;i++) #define clr(x,c) memset…
Sliding Window Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 73426   Accepted: 20849 Case Time Limit: 5000MS Description An array of size n ≤ 106 is given to you. There is a sliding window of size k which is moving from the very left…
An array of size n ≤ 10 6 is given to you. There is a sliding window of size kwhich is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves rightwards by one positi…
题目:http://poj.org/problem?id=2823 单调队列模板. 代码如下: #include<iostream> #include<cstdio> using namespace std; int n,k,a[1000005],mx[1000005],mn[1000005]; int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { scanf("%d&…
题目链接:http://poj.org/problem?id=3017 题意:给你一个长度为n的数列,要求把这个数列划分为任意块,每块的元素和小于m,使得所有块的最大值的和最小 分析:这题很快就能想到一个DP方程 f[ i ]=min{ f[ j ] +max{ a[ k ] }}( b[ i ]<j<i,j<k<=i)     b[ i ]到 i的和大于m 这个方程的复杂度是O(n^2),明显要超时的(怎么discuss都说数据弱呢= =) 然后是优化了,首先当然是要优化一个最大…