UV 11020, uva11020
Ultraviolet A 11020-Efficient Solutions
Question Link
Each person has two attribute values (x, y). For each person (x, y), when there is another person (x', y '), if their property values meet the requirements of X' <x, y' <= y or x' <= x, y' <y, this person will lose the advantage of adding a person each time, and output the current number of advantageous persons
Train of Thought: because each person loses his or her advantage and cannot gain another advantage, he or she can delete these points. In this way, he or she can use a multiset to maintain the point set and add one point each time, use lowerbound and upper_bound to find the position of the vertex next to it for judgment and deletion.
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <set>using namespace std;int t, n;struct Point { int x, y; bool operator < (const Point &c) const {if (x == c.x) return y < c.y;return x < c.x; }};multiset<Point> s;multiset<Point>::iterator it;int main() { int cas = 0; cin >> t; while (t--) {s.clear();cin >> n;Point u;cout << "Case #" << ++cas << ":" << endl;while (n--) { cin >> u.x >> u.y; it = s.lower_bound(u); if (it == s.begin() || (--it)->y > u.y) {s.insert(u);it = s.upper_bound(u);while (it != s.end() && it->y >= u.y) s.erase(it++); } cout << s.size() << endl;}if (t) cout << endl; } return 0;}