HDU 4268 Alice and Bob (Multiset use)

Source: Internet
Author: User

Alice and Bob

Time limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3046 Accepted Submission (s): 995


Problem Descriptionalice and Bob ' s game never ends. Today, they introduce a new game. In this game, both of them has N different rectangular cards respectively. Alice wants to use he cards to cover Bob ' s. The card A can cover the card B if the height of a is not smaller than B and the width of A are not smaller than B. As the best programmer, you is asked to compute the maximal number of Bob's cards that Alice can cover.
Please pay attention this each card can is used only once and the cards cannot be rotated.

Inputthe first line of the input is a number T (T <=) which means the number of test cases.
For each case, the first line was a number N which means the number of cards that Alice and Bob had respectively. Each of the following n (n <= 100,000) lines contains-integers h (H <= 1,000,000,000) and W (w <= 1,000,000,0 XX) which means the height and width of Alice's card, then the following N lines means that of Bob ' s.

Outputfor each test case, output a answer using one line which contains just one number.

Sample Input221 23 42 34 532 35 76 84 12 53 4

Sample Output12

Source2012 ACM/ICPC Asia Regional Changchun Online

Main topic:

This problem is to give you 2 groups containing n different sizes of rectangular blocks, to go to a rectangular block can completely cover the rectangular block B, and each rectangular block can only be used once.

The maximum number of rectangles that can be overwritten.

Problem Solving Ideas:

At first, I looked at a 0 less, want to use O (N2) try to see the data water, the result, decisive T dropped.

In fact, this problem is a related multiset application, we just for A and b two arrays according to the small to large order of W, followed by b[] small and medium A[].W

Added to the multiset, because the condition of the join has satisfied the size of W, now we use the member function in Multiset Upper_bound to find the first

A bigger subscript than a[i].h, and then cut off all of the previous subscripts, which is all we have to find to meet the conditions of the program number.

Remember, every time you use the multiset, you have to clear, otherwise you will have unnecessary results for the subsequent computations.

Code:

1# include<cstdio>2# include<iostream>3# include<Set>4# include<algorithm>5 6 using namespacestd;7 8# define MAX100000+49 Tenmultiset<int>MS; One  A structnode - { -     intw,h; the }a[max],b[max]; -  - intCMP1 (Const structNode & XX,Const structNode &yy) - { +     if(xx.w==YY.W) -         returnXx.h <Yy.h; +     returnXX.W <YY.W; A } at  -  - intMainvoid) - { -     intT;SCANF ("%d",&t); -      while(t-- ) in     { -         intN;SCANF ("%d",&n); to          for(inti =0; I < n;i++ ) +         { -scanf"%d%d",&a[i].w,&a[i].h); the         } *          for(inti =0; I < n;i++ ) $         {Panax Notoginsengscanf"%d%d",&b[i].w,&b[i].h); -         } theSort (a,a+n,cmp1); +Sort (b,b+n,cmp1); A         intAns =0; themultiset<int>:: iterator it; +          for(inti =0, j =0; I < n;i++ ) -         { $              while(J < n&&b[j].w<=A[I].W) $             { - Ms.insert (b[j].h); -J + +; the             } -it =Ms.upper_bound (a[i].h);Wuyi             if(it!=Ms.begin ()) the             { -it--; Wu Ms.erase (it); -ans++; About             } $  -         } - ms.clear (); -printf"%d\n", ans); A     } +  the     return 0; -}

HDU 4268 Alice and Bob (Multiset use)

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.