给出一系列的1*h的矩形,求矩形的最大面积。
如图:

题解链接:点我

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN=;
pair<int,int> ele[MAXN];
int main(){
int height, n;
int w;
int i,j,k;
long long ans, tot, tmp;
int top=;
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
while (scanf("%d", &n) != EOF && n)
{
top = ;
ans = ;
for(i=;i<n;i++){
tmp=;
scanf("%d",&w);
while(top>&&w<ele[top-].first){
long long aans=(long long)ele[top-].first*(ele[top-].second+tmp);
ans=max(ans,aans);
tmp+=ele[top-].second; //这个比较容易忘,这是当前累计的加上之前累计的
top--;
}
ele[top].first=w;
ele[top].second=+tmp;
top++;
}
tmp=;
while(top>){
long long aans=ele[top-].first*(ele[top-].second+tmp);
ans=max(ans,aans);
tmp+=ele[top-].second;
top--;
}
printf("%lld\n", ans); }
return ; }

poj 2559 单调栈 ***的更多相关文章

  1. poj 2059 单调栈

    题意:求柱状图中最大矩形面积. 单调栈:顾名思义就是栈内元素单调递增的栈. 每次插入数据来维护这个栈,假设当前须要插入的数据小于栈顶的元素,那就一直弹出栈顶的元素.直到满足当前须要插入的元素大于栈顶元 ...

  2. Poj 3250 单调栈

    1.Poj 3250  Bad Hair Day 2.链接:http://poj.org/problem?id=3250 3.总结:单调栈 题意:n头牛,当i>j,j在i的右边并且i与j之间的所 ...

  3. [poj 2796]单调栈

    题目链接:http://poj.org/problem?id=2796 单调栈可以O(n)得到以每个位置为最小值,向左右最多扩展到哪里. #include<cstdio> #include ...

  4. uva 1619 - Feel Good || poj 2796 单调栈

    1619 - Feel Good Time limit: 3.000 seconds   Bill is developing a new mathematical theory for human ...

  5. POJ 3044单调栈

    题意: 思路: 单调栈 // by SiriusRen #include <stack> #include <cstdio> using namespace std; stac ...

  6. poj 2082 单调栈 ***

    和poj2082差不多,加了一个宽度的条件 #include<iostream> #include<string> #include<cmath> #include ...

  7. poj 2599 单调栈 ***

    和poj2082差不多,加了一个宽度的条件 #include<cstdio> #include<cmath> #include<algorithm> #includ ...

  8. poj 2559 Largest Rectangle in a Histogram (单调栈)

    http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 6 ...

  9. [POJ 2559]Largest Rectangle in a Histogram 题解(单调栈)

    [POJ 2559]Largest Rectangle in a Histogram Description A histogram is a polygon composed of a sequen ...

随机推荐

  1. Unity3d三大光照渲染介绍

      重要:在目前市面上常见的游戏引擎中,主要采用以下三种灯光实现方式: 顶点照明渲染路径细节 Vertex Lit Rendering Path Details 正向渲染路径细节 Forward Re ...

  2. 面试题52:缺少i的乘积数组

    vector<int> multiply(const vector<int>& A) { int len = A.size(); vector<); result ...

  3. python之字符聊天小工具

    server side: # coding: gb2312#socket server端#获取socket构造及常量from socket import *#''代表服务器为localhostmyHo ...

  4. Bootstrap新手学习笔记——css

    Css模块: 1.网格系统: class前缀:.col-xs-*,.col-sm-*,.col-md-*,.col-lg-* <div class="container"&g ...

  5. Visual Studio Online Integrations-Productivity

                                        原文:http://www.visualstudio.com/zh-cn/explore/vso-integrations-di ...

  6. ASP.NET MVC4中使用Ninject

    1.NuGet获取Ninject.dll 选中项目右键: .NET技术交流群 199281001 .欢迎加入. 2.全局注册  Global.asax.cs //注册Ninject依赖注入全局解析器 ...

  7. 新浪微博客户端(32)-设置相册图片的contentMode

    DJStatusPhotoView.m #import "DJStatusPhotoView.h" #import "UIImageView+WebCache.h&quo ...

  8. CF440C

    C. One-Based Arithmetic time limit per test 0.5 seconds memory limit per test 256 megabytes input st ...

  9. spring JTA多数据源事务管理详细教程

    <context:annotation-config /> <!-- 使用注解的包路径 --> <context:component-scan base-package= ...

  10. 诠释Linux中『一切都是文件』概念和相应的文件类型

    导读 在 Unix 和它衍生的比如 Linux 系统中,一切都可以看做文件.虽然它仅仅只是一个泛泛的概念,但这是事实.如果有不是文件的,那它一定是正运行的进程. 要理解这点,可以举个例子,您的根目录( ...