<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      ~歡迎你!第 AmazingCounters.com 位造訪者

      poj 2559 Largest Rectangle in a Histogram - 單調棧

      Time Limit: 1000MS   Memory Limit: 65536K
      Total Submissions: 19782   Accepted: 6393

      Description

      A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rectangles with the heights 2, 1, 4, 5, 1, 3, 3, measured in units where 1 is the width of the rectangles: 

      Usually, histograms are used to represent discrete distributions, e.g., the frequencies of characters in texts. Note that the order of the rectangles, i.e., their heights, is important. Calculate the area of the largest rectangle in a histogram that is aligned at the common base line, too. The figure on the right shows the largest aligned rectangle for the depicted histogram.

      Input

      The input contains several test cases. Each test case describes a histogram and starts with an integer n, denoting the number of rectangles it is composed of. You may assume that 1<=n<=100000. Then follow n integers h1,...,hn, where 0<=hi<=1000000000. These numbers denote the heights of the rectangles of the histogram in left-to-right order. The width of each rectangle is 1. A zero follows the input for the last test case.

      Output

      For each test case output on a single line the area of the largest rectangle in the specified histogram. Remember that this rectangle must be aligned at the common base line.

      Sample Input

      7 2 1 4 5 1 3 3
      4 1000 1000 1000 1000
      0
      

      Sample Output

      8
      4000
      

      Hint

      Huge input, scanf is recommended.
       
      /*/
      大二這學期開學真是忙爆了。作為一個班干部,天哪。。
      
      好久沒有刷題了,想起以前聽了島娘的一節課,單調棧,好像有點似懂非懂,于是抽時間看了一下,總算是搞通了。。。
      
      將讀入的數據一個個壓棧,獎數據與棧頂進行比較大小,如果這個數比棧頂小,就計算以站頂為高的最大矩形的大小,彈出棧頂。如果這個數比棧頂大,直接就壓進棧。這樣一系列操作之后,就會發現棧里面剩下一個遞增數列,用一個pair來保存此時棧高度和前面達到這個高度的個數,然后按照前面的思想去計算每一個高度最大矩形面積是多大。
      

      AC代碼: /*/

      #include "stdio.h"
      #include "string.h"
      #include "stack"
      #include "algorithm"
      using namespace std;
      typedef long long LL;
      typedef pair<LL,LL> PII;
      const LL MX = 1e5 + 5;
      int main() {
      	LL n,h;
      	while(~scanf("%lld",&n)) {
                if(n==0)break; stack<PII> Q; while(!Q.empty()) { Q.pop(); } LL ans=0; for(LL i=0; i<n; i++) { scanf("%lld",&h); LL Now_Big_W=0; while(!Q.empty() && Q.top().first >= h ) { LL H = Q.top().first; LL W = Q.top().second; Q.pop(); Now_Big_W+=W; ans=max(ans,H*Now_Big_W); } Q.push(PII(h,Now_Big_W+1)); } LL The_number_W=0; while(!Q.empty()){ The_number_W+=Q.top().second; ans=max(ans,Q.top().first*The_number_W); Q.pop(); } printf("%lld\n",ans); } return 0; }

        

        

      posted @ 2016-10-21 01:19  ~HDMaxfun  閱讀(385)  評論(0)    收藏  舉報
      主站蜘蛛池模板: √新版天堂资源在线资源| 精品国产中文字幕懂色| 蜜桃av一区二区高潮久久精品| 国产超碰无码最新上传| 国产午夜精品视频在线播放| 精品国产迷系列在线观看| 亚洲爆乳WWW无码专区| 国产香蕉尹人综合在线观看| 果冻传媒一区二区天美传媒| 在线一区二区中文字幕| 起碰免费公开97在线视频| 中文字幕日韩有码国产| 国产 精品 自在 线免费| 日本一区二区三区在线看| AV喷水高潮喷水在线观看COM| 国产精品久久蜜臀av| 亚洲男人的天堂久久香蕉| 无码人妻丝袜在线视频| 浙江省| 乱人伦人妻中文字幕在线| 日本中文字幕久久网站| 韶山市| 国产一区精品综亚洲av| 男人进女人下部全黄大色视频| 四虎永久精品在线视频| 久久热这里只有精品最新| 日韩精品一区二区三区激情视频| 久久88香港三级台湾三级播放| 国产精品一区二区三区性色 | 久久久无码精品亚洲日韩按摩 | 2019国产精品青青草原| 久久亚洲中文字幕不卡一二区| 清纯唯美经典一区二区| 99RE6在线观看国产精品| 国产精品午夜福利合集| 国产精品日韩中文字幕熟女| 在线观看无码av五月花| 中文字幕久久波多野结衣av| 亚洲人午夜精品射精日韩| 国产乱人偷精品人妻a片| 大肉大捧一进一出好爽视频mba|