51nod-1289 Feeding Frenzy

Source: Internet
Author: User

Title Link: 1289 Feeding frenzy

Idea: If you throw the right fish into the stack. If there is a left fish, let it eat with the fish in the stack. If the fish in the stack is eaten by it, answer +1. The final answer is added to the fish in the stack.

1#include <bits/stdc++.h>2 using namespacestd;3 4 intMain () {5stack<int>S;6     intn, x, Y, ans=0;7scanf"%d", &n);8      while(n--) {9scanf"%d%d", &x, &y);Ten         if(y) { OneS.push (x);Continue; A         } -          while(S.size () && s.top () <x) { - S.pop (); the         } -         if(S.empty ()) ans++; -     } -printf"%d\n", ans+s.size ()); +     return 0; -}

51nod-1289 Feeding Frenzy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.