Problem H. Rectangles Too!

时间限制 8000 ms   内存限制 32 MB

A rectangle in the Cartesian plane is speci ed by a pair of coordinates (x1 , y1) and (x2 , y2) indicating its lower-left and upper-right corners, respectively (where x1 ≤ x2 and y1 ≤ y2). Given a pair of rectangles,A = ((x A 1 , y A 1 ), (x A 2 ,y A 2 )) and B = ((x B 1 , y B 1 ), (x B 2 , y B 2 )), we write A ≤ B (i.e., A "precedes" B), if x A 2 < x B 1 and y A 2 < y B 1 :In this problem, you are given a collection of rectangles located in the two-dimension Euclidean plane. Find the length L of the longest sequence of rectangles (A 1,A 2,…,A L) from this collection such that A 1 ≤ A 2 ≤ … ≤ A L.
 

输入数据

The input fi le will contain multiple test cases. Each test case will begin with a line containing a single integer n (where 1 ≤ n ≤ 100000), indicating the number of input rectangles. The next n lines each contain four integers x i 1 ,y i 1 ,x i 2 ,y i 2 (where -1000000 ≤ x i 1 ≤ x i 2 ≤ 1000000, -1000000 ≤ y i 1 ≤ y i 2 ≤ 1000000, and 1 ≤ i ≤ n), indicating the lower left and upper right corners of a rectangle. The end-of-file is denoted by asingle line containing the integer 0.
 

输出数据

For each input test case, print a single integer indicating the length of the longest chain.
 

样例输入

复制
3
1 5 2 8
3 -1 5 4
10 10 20 20
2
2 1 4 5
6 5 8 10
0

样例输出

复制
2
1

提交

请先 登录

© 2025 FAQs Contact About