9715 相邻最大矩形面积 单调栈
2016-11-14 12:38
260 查看
9715 相邻最大矩形面积
时间限制:1000MS 内存限制:65535K提交次数:0 通过次数:0
题型: 编程题 语言: G++;GCC;VC;JAVA
Description
在X轴上水平放置着 N 个条形图,这 N 个条形图就组成了一个柱状图,每个条形图都是一个矩形,每个 矩形都有相同的宽度,均为1单位长度,但是它们的高度并不相同。 例如下图,图1包含的矩形的高分别为2,1,4,5,1,3,3 单位长度,矩形的宽为1单位长度。
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL; #include <iostream> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <string> const int maxn = 100000 + 20; int dp[maxn][2]; int a[maxn]; int stack[maxn]; int id[maxn]; int n; void work() { for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } a[n + 1] = -1; int top = 1; stack[top] = a[1]; id[top] = 1; for (int i = 2; i <= n + 1; ++i) { while (top >= 1 && a[i] < stack[top]) { dp[id[top]][1] = i; top--; } ++top; stack[top] = a[i]; id[top] = i; } top = 1; stack[top] = a ; id[top] = n; for (int i = n - 1; i >= 0; --i) { while (top >= 1 && a[i] < stack[top]) { dp[id[top]][0] = i; --top; } ++top; stack[top] = a[i]; id[top] = i; } // for (int i = 1; i <= n; ++i) { // printf("%d***\n", dp[i][0]); // } int ans = 0; for (int i = 1; i <= n; ++i) { int t = dp[i][1] - i + i - dp[i][0] - 1; ans = max(ans, t * a[i]); } printf("%d\n", ans); } int main() { #ifdef local freopen("data.txt","r",stdin); #endif while (scanf("%d", &n) != EOF) work(); return 0; }
View Code
相关文章推荐
- SCAU OJ 9715 相邻最大矩形面积
- 算法设计分析:相邻最大矩形面积
- 相邻最大矩形面积
- 相邻最大矩形面积的问题
- Poj 2559 最大矩形面积 v单调栈 分类: Brush Mode 2014-11-13 20:48 81人阅读 评论(0) 收藏
- Poj 2559 最大矩形面积 v单调栈
- POJ2104 最大矩形面积 单调栈
- POJ2082 最大矩形面积 单调栈
- hdu 1505 City Game 最大矩形面积 单调队列
- POJ 2559 题解 最大矩形面积 单调栈
- 连续区域最大矩形面积 POJ 1964 2082 2559 2796 3250 3494
- 最大矩形面积(CCF考题)
- poj 2559 Largest Rectangle in a Histogram 求面积最大的矩形(单调栈)
- 直方图中最大矩形面积
- 数据结构Stack实例(二):求矩形最大面积
- 寻找直方图中面积最大的矩形
- Poj 2559 最大矩形面积
- Terrible Sets(求矩形的最大面积(递增栈))
- 最大矩形求解问题(单调递减栈)
- 51Nod-1102-面积最大的矩形