HDU 4268 Alice and Bob greedy STL O (NLOGN)

Source: Internet
Author: User

B-alice and BobTime limit:5000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i6 4u

Description

Alice 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.

Input

The first line of the input is a number T (T <=) which means the number of the 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.

Output

For each test case, the output an answer using one line which contains just one number.

Sample Input

221 23 42 34 532 35 76 84 12 53 4

Sample Output

1 2 Test instructions: 10W data, A has n cards, B has n cards, then if A.x>=b.x&&a.y>=b.y then a can cover B then ask you to cover the maximum number of questions: Violence very good, O (n^2) Run is, But it will be t so we can find it by two points, or use the STL.
Multiset<int>MySet;Multiset<Int::IteratorIt;Constint MAXN=200000;struct Node{int xY;booloperator< (Const node& B)Const{return x<b. x;}}a[MAXN],b[MAXN];IntMain(){int secN;scanf("%d", &sec);For(int Z=1; z<=sec; z++){MySet.Clear();scanf("%d", &n);For(int I=1; I<=n; I++)scanf("%d%d", &a[I].x, &a[I].y);For(int I=1; I<=n; I++)scanf("%d%d", &b[I].x, &b[I].y);Sort(A+1A+1+n);Sort by x from small to largeSort(b+1B+1+n);Sort by x from small to largeInt J=1;int ans=0;J is a pointer to the position of the B arrayFor(int I=1; I<=n; I++){While(j<=n&&b[j].x<=a[I].x){MySet.Insert(b[j].y); J++;} it=myset.Upper_bound(A[I].yif (Myset. Size () >0&&it !=myset. Begin () It--; if (Myset. Size () >0&& (*it [i].y) Span class= "Sh-cbracket" >{ans++; myset.erase (it);} printf ("%d\n", ans); } return 0;                

HDU 4268 Alice and Bob greedy STL O (NLOGN)

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.