8 条题解
- 
  0
思路:
我们找到左边第一个比他小和右边第一个比它小的,就可以得知这个高度的矩形的宽**代码:
#include<iostream> #include<stack> #define int long long using namespace std; stack<int> st; int h[100005],n,to,l[100005],r[100005],ans; signed main(){ while(cin>>n,n){ for(int i=1;i<=n;i++) cin>>h[i]; h[0]=-1; st.push(0); for(int i=1;i<=n;i++){ while(!st.empty()&&h[i]<=h[st.top()]) st.pop(); l[i]=st.top(); st.push(i); } while(!st.empty()) st.pop(); h[n+1]=-1; st.push(n+1); for(int i=n;i>=1;i--){ while(!st.empty()&&h[i]<=h[st.top()]) st.pop(); r[i]=st.top(); st.push(i); } ans=0; for(int i=1;i<=n;i++){ ans=max(ans,(r[i]-l[i]-1)*h[i]); } cout<<ans<<endl; } return 0; } 
信息
- ID
 - 42
 - 时间
 - 1000ms
 - 内存
 - 128MiB
 - 难度
 - 5
 - 标签
 - 递交数
 - 265
 - 已通过
 - 103
 - 上传者