51Nod 1289 大鱼吃小鱼

来源:互联网 发布:清北学霸 知乎 编辑:程序博客网 时间:2024/06/02 21:18

#include<iostream>#include<stack>using namespace std;int main(){int n;while(cin >> n){stack<int> s;int size,v;int res=0;for(int i=0;i<n;i++){cin >> size >> v;if(v==0 && s.empty()){res++;}else if(v==0){bool flag=0;while(!s.empty()){int cur = s.top();s.pop();if(cur>size) {s.push(cur);flag=1;break;}}if(flag==0) res++;}else{s.push(size);}}while(!s.empty()){s.pop();res++;}cout << res << endl;}}


原创粉丝点击