目录
目录
最大矩形面积
题目
此题很容易想到的一个方法莫过于暴搜了,
代码
#include<cstdio>
#define L 100000 + 5
#define LL long long
#include<iostream>
using namespace std;
inline void read(LL &x){
LL f = 1;
x = 0;
char s = getchar();
while (s < '0' || s > '9'){
if (s == '-')
f = -1;
s = getchar();
}
while (s >= '0' && s <= '9'){
x = x * 10 + s - '0';
s = getchar();
}
x *= f;
}
int n;
LL a[L],max_x;
inline LL max(LL x,LL y){
return x > y ? x : y;
}
int main(){
scanf("%d",&n);
for (register int i = 1;i <= n; ++ i)
read(a[i]);
for (register int i = 1;i <= n; ++ i){
int j = i - 1;
while (a[j] >= a[i])
-- j;
++ j;
int k = i + 1;
while (a[k] >= a[i])
++ k;
max_x = max(max_x,a[i] * (k - j));
}
printf("%lld\n",max_x);
return 0;
}
很真实,再看看时间:
对比一下正解就知道它的吓人之处了
所以做题时,不一定要按要求正解呢,不说多了,看看正解吧