题解 | #大雨吃小鱼#

大雨吃小鱼

https://www.nowcoder.com/practice/77199defc4b74b24b8ebf6244e1793de

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
using namespace std;

int main() {
    int m;
    cin>>m;
    vector<int> fash(m, 0);
    for(int i=0; i<m; i++)
    {
        cin>>fash[i];
    }

    stack<pair<int, int>> s;
    pair<int, int> tops;
    int res=0;
    
    for(int i=m-1;i>=0; i--)
    {
        int counts = 0;
        while(!s.empty() && fash[i] > s.top().first)
        {
            tops = s.top();
            s.pop();
            counts = max(counts+1, tops.second);
        }
        s.push({fash[i], counts});
        res = max(res, counts);
    }
    cout<<res<<endl;
    return 0;
}

全部评论

相关推荐

06-26 10:08
门头沟学院 C++
北京Golang实习,一个月4700,吃住都不报,公司位置在海淀。请问友友怎么看呢?如果要租房的话有什么建议吗
码农索隆:租房肯定是合租了,剩下的钱,差不多够正常吃饭了,看看能不能学到东西吧
点赞 评论 收藏
分享
05-07 17:58
门头沟学院 Java
wuwuwuoow:1.简历字体有些怪怪的,用啥写的? 2.Redis 一主二从为什么能解决双写一致性? 3.乐观锁指的是 SQL 层面的库存判断?比如 stock > 0。个人认为这种不算乐观锁,更像是乐观锁的思想,写 SQL 避免不了悲观锁的 4.奖项证书如果不是 ACM,说实话没什么必要写 5.逻辑过期时间为什么能解决缓存击穿问题?逻辑过期指的是什么 其实也没什么多大要改的。海投吧
点赞 评论 收藏
分享
06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-26 15:18
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务