本文主要是介绍hdu 1506 栈,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:点击打开链接
题目大意:同poj 2796;
题目总结:hdu又被lld坑了
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
__int64 num[100010];
__int64 sum[100010],maxn=-1,tmp;int right[100010],left[100010];int main()
{int n,i,a,b;while(scanf("%d",&n)&&n){for(i = 1; i <= n; i ++){scanf("%I64d",&num[i]);sum[i] = sum[i-1]+num[i];left[i] = right[i] = i;}for(i = 2; i <= n; i ++)while(left[i]>1 && num[left[i]-1]>=num[i])left[i]=left[left[i]-1];for(i=n-1; i; i--)while(right[i]<n && num[right[i]+1]>=num[i])right[i]=right[right[i]+1];maxn=-1;for(i=1; i<=n; i++){tmp=(right[i]-left[i]+1)*num[i];if(tmp>maxn)maxn=tmp;}printf("%I64d\n",maxn);}return 0;
}
这篇关于hdu 1506 栈的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!