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&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