zoukankan      html  css  js  c++  java
  • poj 2599 单调栈 ***

    和poj2082差不多,加了一个宽度的条件

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<iostream>
     6 using namespace std;
     7 const int MAXN=100005;
     8 pair<int,int> ele[MAXN];
     9 int main(){
    10     int height, n;
    11     int w;
    12     int i,j,k,h;
    13     int ans, tot, tmp;
    14     int top=0;
    15     while (scanf("%d", &n) != EOF && n!=-1)
    16     {
    17         top = 0;
    18         ans = 0;
    19         for(i=0;i<n;i++){
    20             tmp=0;
    21             scanf("%d%d",&w,&h);
    22             while(top>0&&h<ele[top-1].first){
    23                 int aans=ele[top-1].first*(ele[top-1].second+tmp);
    24                 ans=max(ans,aans);
    25                 tmp+=ele[top-1].second; //这个比较容易忘,这是当前累计的加上之前累计的
    26                 top--;
    27             }
    28             ele[top].first=h;
    29             ele[top].second=w+tmp;
    30             top++;
    31         }
    32         tmp=0;
    33         while(top>0){
    34                 int aans=ele[top-1].first*(ele[top-1].second+tmp);
    35                 ans=max(ans,aans);
    36                 tmp+=ele[top-1].second;
    37                 top--;
    38         }
    39         printf("%d
    ", ans);
    40 
    41 
    42     }
    43     return 0;
    44 
    45 }
  • 相关阅读:
    通过TomCat获取html文件时中文乱码
    H5小细节
    jquery中自定义函数被事件调用
    CSS-规则声明
    CSS-继承、层叠、特指
    CSS-伪类
    CSS-属性选择器
    CSS-ID和类选择器
    CSS-上下文选择器
    JQ实现多图片预览和单图片预览
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4671001.html
Copyright © 2011-2022 走看看