UV 11020, uva11020

Source: Internet
Author: User

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;}





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.