10396:h.rectanglestime limit:2 Sec Memory limit:128 MB submit:229 solved:33 [Submit][status][web Board] Description
Given N (4 <= n <=) rectangles and the lengths of their sides (integers in the range 1..1,000), write a Progra M that finds the maximum k for which there are a sequence of K of the given rectangles that can "nest", (i.e., some sequenc E P1, P2, ..., Pk, such that P1 can completely fit to P2, P2 can completely fit into P3, etc.).
A rectangle fits inside another rectangle if one of its sides are strictly smaller than the other rectangle ' s and the Remai Ning side is no larger. If the rectangles is identical they is considered not to fit into each other. For example, a 2*1 rectangle fits with a 2*2 rectangle, but not in another 2*1 rectangle.
The list can be created from rectangles in to order and in either orientation.
Input
The first line of input gives a single integer, 1≤t≤10, the number of test cases. Then follow, the for each test case:
* Line 1:a integer N, Given the number ofrectangles n<=100
* Lines 2..n+1:each Line contains-space-separated integers X Y, the sides of the respective rectangle. 1<= X, y<=5000
Output
Output for each test case, a single line with a integer K, the length of the longest sequence of fitting rectangles.
Sample Input
148 1416 2829) 1214 8
Sample Output
2
HINT Source
Seventh session of Henan Provincial race
Puzzle: The number of rectangular nesting, only need to put x from small to large arrangement, looking for lis good; note x is smaller than Y, Lis to upper;
Code:
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include < Algorithm> #include <vector>using namespace std; #define MEM (x, y) memset (x,y,sizeof (×)) #define SI (x) scanf ("%d ", &x) #define SL (x) scanf ("%lld ", &x) #define PI (x) printf ("%d ", x) #define PL (x) printf ("%lld ", x) #define P_ printf ("") const int Inf=0x3f3f3f3f;const double Pi=acos ( -1.0); typedef long LONG ll;struct node{int x,y;friend bool operator < ; (Node A,node B) {if (a.x!=b.x) return a.x<b.x;else return a.y<b.y;}}; Node D[110],dt[110];int Main () {int t,n;si (T), while (t--) {SI (N); int x,y;for (int i=0;i<n;i++) {scanf ("%d%d", &x, &y);d [I].x=min (x, y);d [I].y=max (x, y);} Sort (d,d+n); int k=1;dt[0].x=d[0].x;dt[0].y=d[0].y;if (n==0) {puts ("0"); continue;} for (int i=1;i<n;i++) {while (D[I].X==D[I-1].X&&D[I].Y==D[I-1].Y) i++;d t[k++]=d[i];} /*for (int i=0;i<k;i++) {printf ("%d%d\n", dt[i].x,dt[i].y);} */vector<int>vec;for (int i=0;i<k;i++) {if (Upper_bound (Vec.begin (), Vec.enD (), DT[I].Y) ==vec.end ()) Vec.push_back (DT[I].Y); else *upper_bound (Vec.begin (), Vec.end (), dt[i].y) =dt[i].y;} printf ("%d\n", Vec.size ());} return 0;}
Seventh session of Henan Province H.rectangles (LIS)