E - 秋实大哥去打工

Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu

Appoint description: 
System Crawler  (2016-04-24)

Description

天行健,君子以自强不息。地势坤,君子以厚德载物。

天天过节的秋实大哥又要过节了,于是他要给心爱的妹子买礼物。但由于最近秋实大哥手头拮据,身为一个男人,他决定去打工!

秋实大哥来到一家广告公司。现在有n块矩形墙从左至右紧密排列,每一块高为Hi,宽为Wi。

公司要求秋实大哥找出一块最大的连续矩形区域,使得公司可以在上面贴出最大的海报。

Input

第一行包含一个整数n,表示矩形墙的个数。

接下来n行,每行有两个整数Wi,Hi,表示第i块墙的宽度和高度。

1≤n≤200000,保证Wi,Hi以及最后的答案<231。

Output

最大的连续矩形的面积。

Sample Input


3 4 
1 2 
3 4

Sample Output

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int maxn=200000;
int w[maxn+10],h[maxn+10];
int l[maxn+10],r[maxn+10],x[maxn+10]; int main()
{
int n;
while(~scanf("%d",&n))
{
MM(l,0);MM(r,0);MM(x,0);
for(int i=1;i<=n;i++)
scanf("%d %d",&w[i],&h[i]);
x[1]=1;
for(int i=2;i<=n+1;i++)
x[i]=x[i-1]+w[i-1];//处理每个点的坐标
stack<int> stl;
for(int i=1;i<=n;i++)
{
while(stl.size()&&h[stl.top()]>=h[i]) stl.pop();
l[i]=stl.size()==0?1:stl.top()+1;
stl.push(i);
} stack<int> str;
for(int i=n;i>=1;i--)
{
while(str.size()&&h[i]<=h[str.top()]) str.pop();
r[i]=str.size()==0?n+1:str.top();
str.push(i);
} int maxn=0;
for(int i=1;i<=n;i++)
maxn=max(maxn,(x[r[i]]-x[l[i]])*h[i]);
printf("%d\n",maxn);
}
return 0;
}

  分析:裸的单调栈,需要处理好每个点的下标就好

CDOJ 1069 秋实大哥去打工 单调栈 下标处理的更多相关文章

  1. 2015 UESTC 数据结构专题G题 秋实大哥去打工 单调栈

    秋实大哥去打工 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Descr ...

  2. UESTC_秋实大哥去打工 2015 UESTC Training for Data Structures<Problem G>

    G - 秋实大哥去打工 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Subm ...

  3. uestc poj2559 秋实大哥去打工

    //感觉有必要把这题放博客上待复习 刚刚写解题报告的时候发现自己又不会做这题了 //我不会告诉你这题绝对是命题人抄poj2559 这题使用一个单调递增的栈,栈内存储的元素有两个值,一个高度,一个长度. ...

  4. CDOJ 1070 秋实大哥打游戏 带权并查集

    链接 F - 秋实大哥打游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit ...

  5. CDOJ 1060 秋实大哥与快餐店 字典树 水题

    题目链接 B - 秋实大哥与快餐店 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Sub ...

  6. CDOJ 1057 秋实大哥与花 线段树 区间更新+区间查询

    链接: I - 秋实大哥与花 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submit ...

  7. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

  8. CDOJ 1071 秋实大哥下棋 线段树

    分析:运用扫描线,先从左到右扫描,用纵坐标进行建树, 随着扫描线的右向右移动.不断更新横坐标小于扫描线的车 更新的时候  在树中更新车的纵坐标的位置,把该位置的值变成该车的横坐标 线段树维护的是区间最 ...

  9. cdoj 秋实大哥搞算数

    地址:http://acm.uestc.edu.cn/#/contest/show/95 题目: N - 秋实大哥搞算数 Time Limit: 3000/1000MS (Java/Others)   ...

随机推荐

  1. 四、Kubernetes_V1.10集群部署-master-创建kubeconfig

    1.生成配置文件 # 创建 TLS Bootstrapping Token # export BOOTSTRAP_TOKEN=$( /dev/urandom | od -An -t x | tr -d ...

  2. java期末考试

    水仙花数 package txt; public class shuixianhua { public static void main(String[] args) { // TODO Auto-g ...

  3. show slave status参数详解

    root@localhost (none)>show slave status\G *************************** 1. row ******************** ...

  4. 升级tableau版本

    下载地址: https://www.tableau.com/zh-cn/support/releases 2018以后的版本升级:https://help.tableau.com/current/se ...

  5. Spring MVC 中使用AOP 进行统一日志管理--XML配置实现

    1.介绍 上一篇博客写了使用AOP进行统一日志管理的注解版实现,今天写一下使用XML配置实现版本,与上篇不同的是上次我们记录的Controller层日志,这次我们记录的是Service层的日志.使用的 ...

  6. void *与id类型的相互转换

    void *与id类型相互转换 在MRC下,void *与id类型相互转换完全没问题. id obj = [[NSObject alloc] init]; void *p = (void *)p; o ...

  7. CF 1136C Nastya Is Transposing Matrices

    题目链接:http://codeforces.com/problemset/problem/1136/C 题目分析 看了题目之后,第一想法:任意位置都可以倒置,要是枚举,铁定的超时.所以需要探索规律. ...

  8. AutoLayout and Sizeclasses讲解

    iOS8和iPhone6发布已经过去蛮久了,广大的果粉终于迎来了大屏iPhone,再也不用纠结为大屏买三星舍苹果了…但是对于iOS开发人员来说,迎来了和Android开发开发一样的问题—>各种屏 ...

  9. Struts2.5以上版本There is no Action mapped for namespace [/] and action name [userAction_login] associated with context path []

    分析:Struts2在2.5版本后添加strict-method-invocation(严格方法访问),默认为true,不能使用动态方法调用功能,故需设为false struts.xml设置如下: & ...

  10. 在VMware Vcenter添加一块网卡后,启动虚机找不到网卡,发现有一个ens38(redhat7.5)

    添加一块网卡后,启动虚机找不到网卡,发现有一个ens38 问题:新建虚拟机设置为一块网卡,时候在Vcenter再添加一块网卡,这个问题相信很多网友都见过,今天就来总结一下添加过程中的问题. 由于有以前 ...