poj 2796 Feel Good 单调栈区间问题】的更多相关文章

Feel Good 题意:给你一个非负整数数组,定义某个区间的参考值为:区间所有元素的和*区间最小元素.求该数组中的最大参考值以及对应的区间. 比如说有6个数3 1 6 4 5 2 最大参考值为6,4,5组成的区间,区间最小值为4,参考值为4*(6+5+4)=60 数据范围1<=n<=100000:单调栈做法:对于一个区间,我们需要知道区间的最小值,并且是在出栈的时候更新最优解:这时就可以想到当我们维护的是一个单调递增的栈时,栈顶元素由于当前入栈的元素逼栈顶元素小而要出栈时,这个栈顶元素所代表…
Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20408   Accepted: 5632 Case Time Limit: 1000MS   Special Judge Description Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated…
描述 Given a sequence, we define the seqence's value equals the difference between the largest element and the smallest element in the sequence. As an example, the value of sequence (3, 1, 7, 2) = 7-1 = 6. Now, given a sequence S, output the sum of all…
Feel Good Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories about some period of life. A new idea Bill has recently developed assigns a…
Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8753   Accepted: 2367 Case Time Limit: 1000MS   Special Judge Description Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated…
题目链接:http://poj.org/problem?id=2796 单调栈可以O(n)得到以每个位置为最小值,向左右最多扩展到哪里. #include<cstdio> #include<algorithm> #include<stack> using namespace std; ; int a[maxn]; int l[maxn]; int r[maxn]; long long pre[maxn]; stack< pair<int,int> &g…
http://poj.org/problem?id=2796 题意:给出n个数,问一个区间里面最小的元素*这个区间元素的和的最大值是多少. 思路:只想到了O(n^2)的做法. 参考了http://www.cnblogs.com/ziyi--caolu/archive/2013/06/23/3151556.html的写法,用单调栈可以优化到O(n). 对于每个元素,维护这个元素向前延伸比它大的有多少个,向后延伸比它小的有多少个.即该元素是处于山谷. 那么如何用单调栈维护这个呢? 首先这个栈是单调递…
传送门:http://poj.org/problem?id=2796 题意:给你一串数字,需要你求出(某个子区间乘以这段区间中的最小值)所得到的最大值 例子: 6 3 1 6 4 5 2 当L=3,R=5时这段区间总和为6+4+5=15,最小值为4,所以最后的结果为60. 思路:单调栈的板子题了.没学过单调栈的我只能现学了.单调栈分为单调递增栈,单调递减栈.而这个题呢,要用到单调递增栈.怎么维护单调栈呢?那就是在遇到一个元素大于栈顶元素时,就将该元素加入栈中.(假定即为区间最小值,区间左端点L=…
关于单调栈的性质,和单调队列基本相同,只不过单调栈只使用数组的尾部, 类似于栈. Accepted Code: /************************************************************************* > File Name: 2796.cpp > Author: Stomach_ache > Mail: sudaweitong@gmail.com > Created Time: 2014年07月21日 星期一 22时45…
传送门 Description Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories about some period of life. A new idea Bill has recently developed ass…