Example 3.19 Advantage crowd UVa11020

Source: Internet
Author: User

1. Title Description: Click to open the link

2. Solving ideas: The problem is solved by using multiset. According to test instructions, if we use P (x, y) to denote a person, because people can be the same, so use Multiset. We will find that if all the people have an advantage, then these points show a decreasing trend. If you have just inserted a person, does he have the advantage of how to judge? Just see if the y-coordinate of the point on his left side is smaller than his. And if this person has an advantage, then need to insert this person into the collection, and then start from Upper_bound (P), delete the point of no advantage, note that the deletion should be written as S.erase (it++), because the deletion will cause the pointer to move to the left, so also need it++. Thus, S.size () is the answer at this time.

3. Code:

#include <iostream> #include <algorithm> #include <cassert> #include <string> #include < sstream> #include <set> #include <bitset> #include <vector> #include <stack> #include <map > #include <queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring > #include <cmath> #include <ctime> #include <cctype> #include <functional> #pragma comment ( linker, "/stack:1024000000,1024000000") using namespace std; #define ME (s) memset (s,0,sizeof (s)) #define REP (I,n) for (  int i=0;i< (n); i++) typedef long LONG ll;typedef unsigned int uint;typedef unsigned long long ull;//typedef pair <int,    int> p;struct point{int A, b; BOOL operator< (const POINT&AMP;RHS) const {return a<rhs.a| |    (a==rhs.a&&b<rhs.b);  }};multiset<point>s;multiset<point>::iterator It;int Main () {int T;  scanf ("%d", &t); for (int kase = 1; kase <= T; kase++) {if (Kase > 1) printf("\ n");    printf ("Case #%d:\n", Kase);    int n, a, B;    scanf ("%d", &n);    S.clear ();      while (n--) {scanf ("%d%d", &a, &b);      Point P = (point) {a, b}; it = S.lower_bound (P);//Find the person's location first if (it = = S.begin () | |        (--it)->b > B)//If he left no one   or   his left man the Y value is greater than B, indicating that this person has an advantage and should be added to the set {S.insert (P);        it = S.upper_bound (P);      while (It! = S.end () && it->b >= b) s.erase (it++);    } printf ("%d\n", S.size ()); }} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Example 3.19 Advantage crowd UVa11020

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.