The largest rectangle
 
 
  
   
   | Time limit: | 1.0s | 
 
   
   | Memory Limit: | 256.0MB | 
 
  
 
 
  
   
   | Problem Description n adjacent rectangles are placed on the horizontal axis, the width of each rectangle is 1, and the height of the first (1≤i≤n) rectangle is hi. These n rectangles form a histogram. For example, the height of the six rectangles is 3, 1, 6, 5, 2, 3, respectively.   Find the rectangle with the largest area in the given histogram, and its edges are parallel to the axis. For the example given above, the maximum rectangle as shown in the shaded portion, the area is 10.   Input format The first line contains an integer n, which is the number of rectangles (1≤n≤1000). The second line contains n integers h1, h2, ..., HN, and the adjacent numbers are separated by a space. (1≤hi≤10000). Hi is the height of the first rectangle.The output format outputs a row that contains an integer that is the area of the largest rectangle within a given histogram.  Sample Input 6 3 1 6 5 2 3Sample Output 10 | 
 
  
Problem solving: Hum haha fast use monotone stack
1#include <bits/stdc++.h>2 #defineLL Long Long3 using namespacestd;4 5 structNode {6 LL Height,pos;7Node (LL x =0, LL y =0){8Height =x;9pos =y;Ten     } One } NodeE; A  -Stack<node>Stk; - intMain () { the LL N,a,ans,idx; -      while(~SCANF ("%i64d",&N)) { -          while(!stk.empty ()) Stk.pop (); -Stk.push (Node (0,0)); +          for(LL i = ans =0; I < n; i++) { -scanf"%i64d",&a); +IDX =i; A              while(A <stk.top (). Height) { atans = max (Ans,stk.top (). Height * (i-stk.top (). Pos)); -IDX =stk.top (). Pos; - Stk.pop (); -             } - Stk.push (Node (A,IDX)); -         } in          while(!Stk.empty ()) { -ans = max (Ans,stk.top (). Height * (n-stk.top (). Pos)); to Stk.pop (); +         } -printf"%i64d\n", ans); the     } *     return 0; $}View Code
The largest rectangle of the CCF simulation problem