HDU 1506 Largest Rectangle in a Histogram
2012-03-14 17:54
423 查看
Problem 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 rectangles with the heights 2, 1, 4, 5, 1, 3, 3, measured in units where 1 is the width of the rectangles:
View Code
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 rectangles with the heights 2, 1, 4, 5, 1, 3, 3, measured in units where 1 is the width of the rectangles:
View Code
#include<stdio.h> #include<string.h> int a[100001]; int r[100001]; int l[100001]; int main() { int i,n; __int64 max,temp; while(scanf("%d",&n)&&n) { for(i=1;i<=n;i++) { scanf("%d",&a[i]); l[i]=r[i]=i; } for(i=2;i<=n;i++) { while(l[i]>1&&a[l[i]-1]>=a[i]) l[i]=l[l[i]-1]; } for(i=n-1;i>=1;i--) { while(r[i]<n&&a[r[i]+1]>=a[i]) r[i]=r[r[i]+1]; } max=0; for(i=1;i<=n;i++) { temp=(__int64)(r[i]-l[i]+1)*a[i]; if(max<temp) max=temp; } printf("%I64d\n",max); } return 0; }
相关文章推荐
- hdu1506 Largest Rectangle in a Histogram(DP)
- HDU 1506 Largest Rectangle in a Histogram(DP)
- hdu 1506 Largest Rectangle in a Histogram(求最大的矩形)
- hdu 1506(nyoj 258)Largest Rectangle in a Histogram(最大长方形(二))(单调栈)
- HDU 1506 Largest Rectangle in a Histogram
- hdu 1506 Largest Rectangle in a Histogram
- hdu1506——Largest Rectangle in a Histogram
- HDU-1506-Largest Rectangle in a Histogram(区间DP)
- hdu 1506 Largest Rectangle in a Histogram
- HDU 1506 Largest Rectangle in a Histogram(最大矩形面积)
- HDU-1506 Largest Rectangle in a Histogram 动态规划
- HDU-1506 Largest Rectangle in a Histogram
- hdu 1506(nyoj 258)Largest Rectangle in a Histogram(最大长方形(二))(单调栈)
- hdu 1506 Largest Rectangle in a Histogram
- HDU 1506 Largest Rectangle in a Histogram 分治法 -
- HDU 1506 Largest Rectangle in a Histogram
- hdu1506 Largest Rectangle in a Histogram
- HDU 1506 Largest Rectangle in a Histogram(单调栈)
- poj 2559 & hdu 1506 Largest Rectangle in a Histogram 笛卡尔树
- HDU 1506 Largest Rectangle in a Histogram(dp求最大子矩阵和)