zoukankan      html  css  js  c++  java
  • 51Nod 1289 大鱼吃小鱼 栈的简单模拟

    传送门:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1289

    emmmmmm……

     大概就是……①栈空:向左右,最终必然生存(嘛~毕竟速度都是一样的,位置靠左向左游,当然追不上啦~)

                          ②栈非空:a.向右游,进栈;b.向左游,判断与栈中鱼的大小(直至向左游的鱼被吃或必然生存到最后),栈中的大,鱼的数量-1,不对栈做处理,直接跳出循环,栈中的                             鱼小,出栈,数量-1,继续循环

    #include<iostream>   
    #include<algorithm>
    #include<vector> 
    #include<string.h>
    #include<stack>
    using namespace std;
    typedef long long ll;
    const int MAX=5e4+5;
    string s;
    int n,t;
    int main()
    {
        while(cin>>n)
        {
         stack<int>fish;
         int cnt=n,v,d;
         for(int i=0;i<n;i++)
         {
             cin>>v>>d;
             if(d==1) fish.push(v);
             else if(d==0)
             {
             while(!fish.empty())
               {
               if(v>fish.top())    
               {
                 fish.pop();
                 cnt--;
               }
               else 
                {
                  cnt--;
                  break;
                }
             }
           }
         }
         cout<<cnt<<endl;
        } 
        return 0;
    }
  • 相关阅读:
    leetcode
    leetcode
    leetcode
    leetcode
    Postman
    Fiddler抓百度和bing搜索包
    Jmeter脚本录制
    Android Studio使用Maven国内镜像
    Open Live Writer
    PureXXX使用手记
  • 原文地址:https://www.cnblogs.com/Egoist-/p/7625968.html
Copyright © 2011-2022 走看看