POJ 2559】的更多相关文章

Submit Status Practice POJ 2559 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 hi…
[POJ 2559]Largest Rectangle in a Histogram 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 s…
// poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的是数据结构做.也能够递推做.眼下仅仅会数据结构的 // // 对于每一个高度h,求一个左边界L和右边界R,分别表示的意义是 // L是下标为j的矩形的高度的hj小于当前h的最大的j的值. 则依据定义 // 我们能够知道j到i之间的h都是大于当前的hi的. // R是下标为k的矩形的高度的hk大于当前…
题目传送门 /* 题意:宽度为1,高度不等,求最大矩形面积 stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极限情况 st[]里是严格单调递增,若不记录的话还要O(n)的去查找L,R,用栈的话降低复杂度 */ #include <cstdio> #include <cstring> #include <algorithm> #include <stack> #inclu…
http://poj.org/problem?id=2559 题意:就是找出可以完整连接的最大的矩形面积. 思路:找出单独的一块矩形,往两边延伸,记录两边的比他高的矩形是在哪个位置,然后最右的位置减去最左边的矩形的位置.就是这个矩形最大可构成的面积. 但是,如果一个一个用循环去做的话,结果是必定超时的,所以这里要用到单调栈. 比如找出最左边的比目标矩形要高的矩形的位置的代码 while(!s.empty()) //对栈首先进行清空. s.pop(); s.push(); //入栈一个边界位置.…
题目地址:http://poj.org/problem?id=2559 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 th…
http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12297   Accepted: 3974 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base lin…
[题目链接] http://poj.org/problem?id=2559 [题目大意] 给出一些宽度为1的长方形下段对其后横向排列得到的图形,现在给你他们的高度, 求里面包含的最大长方形的面积 [题解] 我们枚举每个位置的最大高度全部被保留时得到的最优解,那么答案一定被包含在其中, 那么题目转化为求出每个高度左右两边最近的比其低的位置,可以用单调栈完成. [代码] #include <cstdio> #include <algorithm> using namespace std…
[题目链接] http://poj.org/problem?id=2559 [算法] 单调栈 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #includ…
题目链接:http://poj.org/problem?id=2559 思路:单调栈 什么是单调栈? 单调栈,顾名思义,就是单调的栈,也就是占中存的东西永远是单调(也就是递增或递减)的 如何实现一个单调栈呢?过程很简单.假设栈中已有了若干单调递增的元素,此时我们又有了一个元素,如果这个元素比栈顶元素大,则直接入栈:反之,不断弹出当前元素,直到栈顶元素比之前小为止.(这里实现的是一个单调递增栈,递减栈和递增栈的过程一样) 为什么这道题可以用单调栈? 假设矩形的高度从左到右递增,那么答案是多少?显而…