zoukankan      html  css  js  c++  java
  • NYOJ 228最大长方形(二)

     
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 #define max(a,b) a>b?a:b
     6 int stack[100010]={-2},len[100010];
     7 int main()
     8 {
     9     int t,i,w,h,top;
    10     long long result;
    11     while(scanf("%d",&t)!=EOF)
    12     {
    13         if(t==0)continue;
    14         top = -1;
    15         result = 0;
    16         for(i=0; i<=t; ++i)  //要多输入一个数来和最后一个数比较
    17         {
    18             if(i<t)    scanf("%d",&h);
    19             else    h = -1;
    20             if(stack[top]<h || top < 0)
    21             {
    22                 stack[++top] = h;
    23                 len[top] = 1;
    24             }
    25             else
    26             {
    27                 w = 0;
    28                 while(stack[top] >= h && top >= 0)
    29                 {
    30                     result = max(result, (long long)stack[top]*(w + len[top]));
    31                     w += len[top--];
    32                 }
    33                 if(h > 0)
    34                 {
    35                     stack[++top] = h;
    36                     len[top] = w + 1;    //这是很关键的一步,要仔细的品味一番其中的精妙之处
    37                 }
    38             }
    39         }
    40         printf("%lld\n",result);
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    为什么用strlcpy取代strncpy
    linux系统调用和库函数调用的区别
    VC、PE和天使投资是什么意思?有什么区别?
    AWS使用心得:当初我曾错过的那些宝贵经验
    bzoj 2208: [Jsoi2010]连通数
    android学习笔记(5)Activity生命周期学习
    Nginx 进程间通信
    手写一个节点大小平衡树(SBT)模板,留着用
    JavaFX学习之道:JavaFX之TableView
    Docker 命令行和后台參数
  • 原文地址:https://www.cnblogs.com/yaling/p/3005958.html
Copyright © 2011-2022 走看看