标签:
题目链接:HDU - 1506
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 #define inf 0x7fffffff 8 using namespace std; 9 typedef long long LL; 10 const int maxn=100000+10; 11 12 int n; 13 int l[maxn],r[maxn],an[maxn]; 14 15 int main() 16 { 17 while (scanf("%d",&n)!=EOF && n) 18 { 19 for (int i=1 ;i<=n ;i++) {scanf("%d",&an[i]);l[i]=r[i]=i;} 20 an[0]=an[n+1]=-1; 21 l[0]=l[n+1]=r[0]=r[n+1]=0; 22 for (int i=1 ;i<=n ;i++) 23 { 24 while (an[l[i]-1 ]>=an[i]) 25 l[i]=l[l[i]-1 ]; 26 } 27 for (int i=n ;i>=1 ;i--) 28 { 29 while (an[r[i]+1 ]>=an[i]) 30 r[i]=r[r[i]+1 ]; 31 } 32 LL ans=0; 33 for (int i=1 ;i<=n ;i++) 34 { 35 LL area=(LL)(r[i]-l[i]+1)*(LL)an[i]; 36 if (area>ans) ans=area; 37 } 38 printf("%I64d\n",ans); 39 } 40 return 0; 41 }
hdu 1506 Largest Rectangle in a Histogram 构造
标签:
原文地址:http://www.cnblogs.com/huangxf/p/4458791.html