F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Horizontal and Vertical Rays

Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 386    Accepted Submission(s): 124


Problem Description
There are H horizontal rays and V vertical rays. A horizontal ray is a straight line which originates at some point and extends infinitely far to the right (towards increasing X coordinates). A vertical ray is a straight line which originates at some point and extends infinitely far down (towards decreasing Y coordinates). A horizontal ray whose origin is (Xh,Yh) touches a vertical ray whose origin is (Xv,Yv) if Xh<=Xv and Yh<=Yv.
You must choose a subset S consisting of the minimum number of vertical rays such that each horizontal ray is touched by at least one vertical ray in S. It is guaranteed that it will always be possible to choose such a subset for the given test data.
 

Input
The first line of input contains an integer number T, representing the number of test cases to follow. The first line of each test case contains 2 integer numbers: H (1<=H<=100.000) and V (1<=V<=100.000). The next H lines contain 2 integers each: X and Y, representing the (X,Y) coordinates of the origins of the horizontal rays. The next V lines contain 2 integers each: X and Y, representing the (X,Y) coordinates of the origins of the vertical rays. All the X and Y coordinates in the input are in the range 0 ... 50.000.000.
 

Output
For each of the T test cases, in the order given in the input, print one line containing the minimum number of vertical rays chosen.
 

Sample Input
1 3 3 1 6 4 4 6 2 3 8 5 7 9 4
 

Sample Output
2
 

Hint

The solution might consist of the second and third vertical rays. Another solution could be formed by the first and the third vertical rays.


 

Author
Mugurel Ionut Andreica
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 18:38:40, Gzip enabled