标签:int() iostream bootstrap update addclass tns .net stat queue
【问题描写叙述】
近期,afy决定给TOJ印刷广告,广告牌是刷在城市的建筑物上的。城市里有紧靠着的N个建筑。
afy决定在上面找一块尽可能大的矩形放置广告牌。我们如果每一个建筑物都有一个高度。
从左到右给出每一个建筑物的高度H1,H2…HN,且0<Hi<=1,000,000,000,而且我们如果每一个建筑物的宽度均为1。
要求输出广告牌的最大面积。
【输入例子】
6
5 8 4 4 8 4
【输出例子】
24
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxn 400000 + 10
int L[maxn], R[maxn];
int pos[maxn];
int a[maxn];
int n;
void get_left()
{
int head = 1, tail = 0;
for(int i = 1; i <= n; i++)
{
while(head <= tail && a[pos[tail]] >= a[i])
tail--;
L[i] = i - pos[tail] - 1;
pos[++tail] = i;
}
}
void get_right()
{
int head = 1, tail = 0;
pos[tail] = n + 1;
for(int i = n; i >= 1; i--)
{
while(head <= tail && a[pos[tail]] >= a[i])
tail--;
R[i] = pos[tail] - i - 1;
pos[++tail] = i;
}
}
int main()
{
while(~scanf("%d", &n))
{
memset(L, 0, sizeof L);
memset(R, 0, sizeof R);
for(int i = 1; i <= n; i++)
scanf("%d", a + i);
get_left();
get_right();
long long ans = -1;
for(int i = 1; i <= n; i++)
ans = max(ans, ((long long)L[i] + R[i] + 1) * a[i]);
printf("%I64d\n", ans);
}
return 0;
}
/*
6
5 8 4 4 8 4
*/
对于每个建筑物,要知道往左到哪一个建筑第一个高度比它低,知道往右走哪一个建筑物第一个高度比它低。 能够用dp,也能够用单调队列。
首先从左往右...

。。 于是

线段树: #include #include #include using namespace std...

0条评论