hdu 1506 히 스 토 그램 에서 가장 큰 사각형 (단조 로 운 스 택)
1390 단어 HDU
동 그 라 미 를 칠 수 있 는 최대 장방형 의 면적 이 얼마나 되 는 지 물 어보 세 요.
생각:http://blog.csdn.net/dgq8211/article/details/7740610
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
#define ll __int64
struct Node
{
int wid;
ll hi;
ll s;
};
Node node[100000+1000];
int main()
{
int n,h;
int i,j,k;
int l,r;
while(scanf("%d",&n),n)
{
stack<Node> q;
ll maxx=0;
Node now;
now.hi=-1;
now.wid=0;
q.push(now);
for(i=0;i<=n;i++)
{
//printf("%d
",i);
if(i!=n) scanf("%d",&h);
else h=0;
if(h>q.top().hi)
{
now.hi=h;
now.wid=1;
q.push(now);
}
else
{
int cnt=0;
while(q.top().hi>=h)
{
now=q.top();
q.pop();
maxx=max(maxx,(cnt+now.wid)*now.hi);
cnt+=now.wid;
}
now.wid=cnt+1;
now.hi=h;
q.push(now);
}
}
printf("%I64d
",maxx);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
hdu4671(다교리그 7--수 시뮬레이션)클릭하여 링크 열기 제목: n과 서버, m개의 데이터베이스가 있고 모든 데이터베이스는 서버를 연결해야 하지만 모든 데이터베이스는 서버를 연결하는 우선순위가 있습니다.모든 데이터베이스의 서버 우선순위를 구하다.또한 한...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.