题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506
题意:给定一个条形统计图,找出一个矩形可以覆盖的最大面积
开两个数组r[](right),l[](left),
分别记录左边和右边能构成矩形的最远的边
#include
#define maxint 200000
__int64 a[maxint];
__int64 l[maxint];
__int64 r[maxint];
int main(){
//freopen("1010.txt","r",stdin);
int n,i,temp;
while(scanf("%d",&n)&&n){
__int64 max=0;
for(i=0;i
scanf("%I64d",&a[i]);
}
l[0]=0;
r[n-1]=n-1;
for(i=1;i
int t=i;
while(t>0&&a[i]<=a[t-1]){
t= l[t-1];
}
l[i]=t;
}
for(i=n-2;i>=0;i--){
int t=i;
while(t<=a[t+1]){
t=r[t+1];
}
r[i]=t;
}
for(i=0;i
{
temp=(r[i]-l[i]+1)*a[i];
if(temp>max){
max=temp;
}
}
printf("%I64d\n",max);
}
return 0;
}
本题加强版:http://acm.hdu.edu.cn/showproblem.php?pid=1505
题解:http://blog.sina.com.cn/s/blog_9635e5ef0101bavh.html