• 洛谷P1165 日志分析 栈


    洛谷P1165 日志分析

    在这道题中 栈st[ i ] 表示的有点特殊
    st[ i ] 表示的st[ 1 ]--st[ i ] 中最大的值

     1 #include <bits/stdc++.h> 
     2 #define For(i,j,k) for(int i=j;i<=k;i++) 
     3 using namespace std ; 
     4 
     5 const int N = 200011 ; 
     6 int Q,type,top,v ; 
     7 int st[N] ; 
     8 
     9 inline int read() 
    10 {
    11     int x = 0 , f = 1 ; 
    12     char ch = getchar() ; 
    13     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar(); } 
    14     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar(); } 
    15     return x * f ; 
    16 }
    17 
    18 int main() 
    19 {
    20     Q = read() ; 
    21     while(Q--) {
    22         type = read() ;  
    23         if(type==0) {
    24             st[++top] = read() ; 
    25             st[top] = max(st[top],st[top-1]) ; 
    26         }
    27         else if(type==1) top = max(0,top-1) ;   // 防止 栈空了还在不停退栈 
    28         else printf("%d
    ",st[top]) ; 
    29     }
    30     
    31     return 0 ; 
    32 }
  • 相关阅读:
    一些前台技巧
    javascript中的面向对象
    vs.net 常用快捷键
    js和C#中的进制转换方法
    MFC中CDC相关图形,文本的一些使用方法(转)
    poj1505
    poj1401
    poj2533
    poj1504
    poj1384
  • 原文地址:https://www.cnblogs.com/third2333/p/7237486.html
Copyright © 2020-2023  润新知