zoukankan      html  css  js  c++  java
  • 单调栈运用2----(xdoj-1156)

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int N=1e5+7;
     4 int num[N];
     5 int len;
     6 int top;
     7 int t;
     8 deque <int> q;
     9 int main ()
    10 {
    11   int n;
    12   while (~scanf ("%d",&n) )           {
    13     while (!q.empty()) q.pop_back();
    14     len=t=0;
    15     top=1;
    16     while (n--) {
    17       int op,x;
    18       scanf ("%d",&op);
    19       if (op==1) {
    20         scanf ("%d",&x); x-=t;
    21         num[++len]=x;
    22         while (!q.empty()&&num[q.back()]<=x) q.pop_back();
    23         q.push_back(len);
    24       }
    25       else if (op==2) { // 想一想为什么要加括号 ?否则1句和2句就要连接在一块了
    26         if ( (top++)==q.front() )  q.pop_front(); //1
    27       }  
    28       else                                        // 2
    29         printf ("%d
    ",num[q.front()]+t); 
    30       t++;
    31     }
    32   }
    33   return 0;
    34 }
    抓住青春的尾巴。。。
  • 相关阅读:
    1.8 Hello World添加menu
    1.7 HelloWorld 添加视图
    1.6 Hello World
    1.5 组件开发基础
    awk
    sed
    grep / egrep
    Shell基础知识
    和管道符有关的命令
    Shell变量
  • 原文地址:https://www.cnblogs.com/xidian-mao/p/8611736.html
Copyright © 2011-2022 走看看