HDU 4268 Alice and Bob (Multiset)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4268

The question is: ask you the maximum number of Bob cards that Alice can cover. Card cannot be flipped

Idea: First we sort the cards by height regardless of the type, and then we judge the card type in sequence. If it is Bob's card, we put the width of his card into Multiset, if Alice's card is used, find the one with the largest width in Multiset and delete it.


# Include <cstdio> # include <iostream> # include <cstring> # include <cmath> # include <algorithm> # include <set> using namespace STD; const int maxn = 200005; struct node {int H, W, ID;} node [maxn]; bool CMP (node T1, node T2) {If (t1.h! = T2.h) return t1.h <t2.h; If (t1.w! = T2.w) return t1.w <t2.w; return t1.id <t2.id;} Multiset <int> S; Multiset <int>: iterator ite; int main () {int N, I, t; scanf ("% d", & T); While (t --) {scanf ("% d", & N); for (I = 1; I <= 2 * n; I ++) {scanf ("% d", & node [I]. h, & node [I]. w); node [I]. id = (I <= N);} Sort (node + 1, node + 2 * n + 1, CMP); S. clear (); int sum = 0; for (I = 1; I <= 2 * n; I ++) {If (node [I]. id = 0) s. insert (node [I]. w); else {If (S. empty () | node [I]. W <* (S. begin () continue; ite = S. upper_bound (node [I]. w); // find ite --; sum ++; S. erase (ITE); // Delete} printf ("% d \ n", sum);} return 0 ;}


HDU 4268 Alice and Bob (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.