Application of UVA 11020 efficient Solutions+multiset

Source: Internet
Author: User

Topic Link: Click to enter
First of all, it's easy to see that we actually just maintain a set of dominant groups; If you join a new person, let's start by looking at whether someone in the dominant crowd will let the person lose his or her edge, and if not, insert the person into the collection, but notice that the person's insertion may leave others with an advantage. So it is required to be able to support fast query and modify operations, and multiset can meet this requirement.
The code is as follows:

#include <iostream>#include <cstdio>#include <cstring>#include <set>using namespace STD;structpoint{intb;the elements in///set are sorted by x    BOOL operator< (Constpoint& RHS)Const{returna<rhs.a| |    (a==rhs.a&&b<rhs.b); }}; multiset<Point>S multiset<Point>:: Iterator it;intMain () {//freopen ("In.txt", "R", stdin);    intTscanf("%d", &t); for(intCase=1; case<=t; case++) {if(case!=1)printf("\ n");printf("Case #%d:\n", case);intN,a,b;scanf("%d", &n); S.clear (); while(n--) {scanf("%d%d", &a,&b);            Point p= {a, b}; it = S.lower_bound (P);/// Find the first element less than p in a red-black tree            if(It==s.begin () | | (--it)->b >=b)// If p also has advantages{S.insert (P); it = S.upper_bound (P);the elements after///it will be affected.                 while(It!=s.end () &&it->b >=b) S.erase (it++);/// Remove the person who loses the advantage}printf("%d\n", S.size ()); }    }return 0;}

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

Application of UVA 11020 efficient Solutions+multiset

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.