1289 Feeding Frenzy
Base time limit: 1 seconds space limit: 131072 KB there are n fish each fish's position and size are different, they swim along the x-axis, some left, some to the right. Swimming speed is the same, two fish meet big fish will eat small fish. The size of each fish and the direction of the swim are given from left to right (0 means left and 1 for right). How many fish can be left after asking long enough? Input
Line 1th: 1 number N, indicating the number of fish (1 <= n <= 100000). 2-n + 1 lines: Two numbers per line a[i], B[i], separated by a space, respectively, the size of the fish and the direction of the swimming (1 <= a[i] <= 10^9,b[i] = 0 or 1,0 means left, 1 to the right).
Output
Output 1 numbers, indicating the number of fish that are eventually left.
Input example
54 03 12 01 05 0
Output example
2
#include <iostream>#include<stack>#defineN 100005using namespacestd;intMain () {stack<int>s; intn,a,b,m; scanf ("%d",&N); M=N; while(n--) {scanf ("%d%d",&a,&b); if(b==1) S.push (a); if(b==0) { while(!S.empty ()) { if(A>s.top ()) {S.pop (); m--;} Else{m--; Break;} }}} printf ("%d\n", M); return 0;}
1289 Feeding Frenzy