Portal : https://vjudge.net/contest/357926#problem/G
题目:On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (ai, bi), and the coordinates of the i-th blue point are (c_i, d_i).
A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.
At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
The meaning of problems: there are n points red and blue-n points in the plane, the red and blue dots between the pairs. If the points a and b, a red dot, a blue dot b, b in a lower left corner, i.e., x and y coordinates of a relatively small b, then these two points can be paired, the two paired and other points can not be paired, you can find the maximum number of pairing
Thinking: because when a, b, x and y are relatively small, these two points can be paired, i.e. between the two sides can be built Representative (herein labeled with flag bit array).
1 / * Maximum Matching: ① ② built FIG edged portion sequentially traverse the left point which determines matching ③find * / 2 / * First Come, let let * / . 3 #include <the iostream> . 4 the using namespace STD; . 5 const int N = 110 ; . 6 int match [N]; // point corresponding to the right value . 7 BOOL VIS [N], in Flag [N] [N]; // VIS weight determination has not looked for . 8 struct Node { . 9 int X, Y; 10 } R & lt [N], B [N]; // red and blue dots . 11 int n-; 12 is BOOL Find (int X) // to find blue red point corresponding to a point 13 is { 14 for ( int I = . 1 ; I <= n-; I ++) // enumerate all points blue 15 { 16 IF (VIS [I! ] && in Flag [X] [I]) // the blue dots are not viewed and can be matched with the red dot . 17 { 18 is VIS [I] = . 1 ; . 19 IF (match [I] == 0 || Find ( match [I])) 20 is { // point not matching the blue through the blue dot || been matched by a red dot but may also match other 21 is match [I] = X; 22 is return . 1; 23 } 24 } 25 } 26 return 0; 27 } 28 int main()//主函数 29 { 30 cin>>n; 31 for(int i=1;i<=n;i++) cin>>r[i].x>>r[i].y; 32 for(int i=1;i<=n;i++) cin>>b[i].x>>b[i].y; 33 for(int i=1;i<=n;i++) 34 { 35 for(int j=1;j<=n;j++) 36 { 37 if(r[i].x<b[j].x&&r[i].y<b[j].y) 38 { 39 flag[i][j]=1;//两者可以配对 40 } 41 } 42 } 43 long long ans=0; 44 for(int i=1;i<=n;i++) 45 { 46 memset(vis,0, The sizeof (VIS)); 47 IF (Find (I)) // maximum matching 48 ANS ++ ; 49 } 50 COUT ANS << << endl; 51 is }