题目链接:http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24259 Accepted: 7844 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common bas…
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rectang…
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26012 Accepted: 8416 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal wi…
Largest Rectangle in a Histogram http://poj.org/problem?id=2559 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题思路 单调栈的经典题(嫌弃字多可以先看后面的示例再来看这个思路) 显然,最终的子矩形高度一定和某一个矩形相等(反证).因此一个暴力的做法就是枚举每一个矩形,然后往两边扩散.在它左侧找到第一个高度比它小的,右侧也一样.则可以求出最大可扩散宽度,乘上高度即可以更新答案.复杂度O(n2) 如果说要优化刚才…
Largest Rectangle in a Histogram 这么经典的题硬是等今天碰到了原题现场懵逼两小时才会去补题...废话不多说: 题意:截取一个矩形使其面积最大,随你怎么截,反正面积要最大.输出最大面积,注意爆int. 思路:dp或单调队列.核心思路是从一个小矩形往两边扩散,分别找两边第一个小于这个矩形的位置,其中面积就是这个小矩形与区间长度的乘积,我们预处理出所有的小矩形的这两个端点值,然后扫一遍即可更新到最…