UVA LA 7146 2014 Shanghai Asian Race (greedy)

Source: Internet
Author: User

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& category=648&problem=5158&mosmsg=submission+received+with+id+1708713

/**uva LA 7146 2014 Shanghai Asian Race (greedy) topic: Given the number of soldiers and each soldier's attack and defensive power, if the two soldiers to fight, one side of the attack is greater than the other side of the defensive force, then successfully killed, may have to kill each other to ask where we can all kill the place Soldier's case, ask us how many of the remaining soldiers are the problem-solving ideas: This last year at the scene did not write out = = First of all to ensure that the local people are to be killed, then the attack of our soldiers descending order, the enemy soldiers in descending order of defense. Enumerate the enemy's soldiers, and multiset all our soldiers with more damage than their defensive forces, and then choose our soldiers with the first defensive force greater than the current enemy's attack, and if not, remove our soldiers with the lowest defensive force */#include &LT;STR ing.h> #include <stdio.h> #include <algorithm> #include <iostream> #include <set>using    Namespace Std;typedef long Long ll;const int maxn=100005;int m,n;struct note{int x, y;    BOOL Operator < (const note &other) const {return x>other.x;    }}a[maxn],b[maxn];int Main () {int t,tt=0;    scanf ("%d", &t);        while (t--) {scanf ("%d%d", &n,&m);        for (int i=0;i<n;i++) {scanf ("%d%d", &a[i].x,&a[i].y);        } for (int j=0;j<m;j++) {scanf ("%d%d", &b[j].y,&b[j].x);        } sort (a,a+n);        Sort (b,b+m); Multiset <inT> St;        int p=0,ans=n; for (int i=0;i<m;i++) {while (b[i].x<=a[p].x&&p<n) {St.insert            (A[P++].Y);                } if (St.empty ()) {ans=-1;            Break            } multiset<int>::iterator It=st.upper_bound (B[I].Y);                if (It==st.end ()) {St.erase (St.begin ());            ans--;        } else St.erase (it);    } printf ("Case #%d:%d\n", ++tt,ans); } return 0;} /**23 25 77 31 24 42 22 13 41 105 6*/


UVA LA 7146 2014 Shanghai Asian Race (greedy)

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.