#include <iostream> #include <stack> #include <queue> using namespace std; stack<int> s; queue<int> q; int main() { int n; cin>>n; for (int i = 0; i < n; ++i) { int flag=0,x=0; scanf("%d %d",&x,&flag); if (flag == 1){ s.push(x); }else if (s.empty() && flag==0){ q.push(x); }else{ while(!s.empty()){ int a = s.top(); if (x>a) s.pop(); else{ break; } } if (s.empty()) q.push(x); } } cout<<s.size()+q.size()<<endl; return 0; }
这题的样例里好像混入了什么奇怪的字符,本地测试过不了(可能只有我过不了)
#include <bits/stdc++.h> using namespace std; typedef pair <int,int> PII; vector <PII> vec; stack <PII> stk; int main() { int N; cin >> N; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; vec.push_back(make_pair(a, b)); } for (int i = 0; i < N; i++) { if (stk.empty()) { stk.push(vec[i]); } else { int d = vec[i].second; int topd = stk.top().second; int s = vec[i].first; int stks = stk.top().first; if (d < topd && s > stks) { // judge empty write fisrt !!! // 1 0 1 1 0 while (stk.size() != 0 && stk.top().first < s && stk.top().second != 0) { // cout << stk.top().first << endl; stk.pop(); } if (stk.size() == 0) { stk.push(vec[i]); } else if (stk.top().second == 0) { stk.push(vec[i]); } } else if (d >= topd) { stk.push(vec[i]); } } } cout << stk.size(); return 0; }
include include using namespace std; int main(){ int height; int lor; int N; cin>>N; int cnt = 0; stack rightStack; int flag = 0; for(int i =0;i>height; cin>>lor; if(lor==0){ if(rightStack.empty()){ cnt++; continue; } while(!rightStack.empty()){ if(rightStack.top()<height){ rightStack.pop(); } else{ flag = 1; break; } } if(!flag) cnt++; } else{ rightStack.push(height); } } while(!rightStack.empty()){ rightStack.pop(); cnt++; } cout<<cnt; return 0; }
using namespace std; int main(){ int height; int lor; int N; cin>>N; int cnt = 0; stack rightStack; int flag = 0; for(int i =0;i>height; cin>>lor; if(lor==0){ if(rightStack.empty()){ cnt++; continue; } while(!rightStack.empty()){ if(rightStack.top()<height){ rightStack.pop(); } else{ flag = 1; break; } } if(!flag) cnt++; } else{ rightStack.push(height); } } while(!rightStack.empty()){ rightStack.pop(); cnt++; } cout<<cnt; return 0; }
这题的样例里好像混入了什么奇怪的字符,本地测试过不了(可能只有我过不了)