51nod

题目链接:1289 大鱼吃小鱼

思路:如果把向右的鱼丢进栈里。如果出现向左的鱼,那么让它跟栈里的鱼互吃。如果栈里的鱼都被它吃光,那么答案+1。最后答案加上栈里的鱼。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main() {
 5     stack<int> S;
 6     int n, x, y, ans=0;
 7     scanf("%d", &n);
 8     while(n--) {
 9         scanf("%d%d", &x, &y);
10         if(y) {
11             S.push(x); continue;
12         }
13         while(S.size() && S.top() < x) {
14             S.pop();
15         }
16         if(S.empty()) ans++;
17     }
18     printf("%d
", ans+S.size());
19     return 0;
20 }
原文地址:https://www.cnblogs.com/fredy/p/5867004.html