海底大作戰大魚吃小魚小游戲,51Nod 1289 大魚吃小魚 棧的簡單模擬

 2023-10-18 阅读 19 评论 0

摘要:傳送門:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1289 emmmmmm…… 海底大作戰大魚吃小魚小游戲。?大概就是……①棧空:向左右,最終必然生存(嘛~畢竟速度都是一樣的,位置靠左向左游,當然追不上啦~

傳送門: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;
}

?

233樂園大魚吃小魚、轉載于:https://www.cnblogs.com/Egoist-/p/7625968.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/146381.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息