Place n cars on a n * n board so that they cannot attack each other (neither of them can be in the same row or column, for the I-th car, it can only be placed in a rectangle area (xli, yli). The vertices in the upper left corner of the rectangle are (xli, yli ), the vertex coordinates in the lower right corner are (xri, yri), 1 ≤ I ≤ n, 1 ≤ xli ≤ xri ≤ n, 1 ≤ yli ≤ yri ≤ n. train of Thought: in fact, the x-axis range and Y-axis range of each car area can be viewed independently. The areas of each car on the X-axis are [xl1, xr1], [xl2, xr2 ], [xl3, xr3 ]... on the Y axis, the region is [yl1, yr1], [yl2, yr2], [yl3, yr3 ]... if a piece is placed in each area on the X or Y axis without conflict, the condition is met. The judgment method is maintained by the priority queue. Each time the [l, r] interval is selected to be the smallest and the r interval is the smallest, we also need to maintain a number (maxx) that has been placed in the current directory. If l <maxx exists, modify this node, change its l to maxx, and then put it into the queue. [Cpp]/* ultraviolet A 11134 Fabled Rooks greedy, priority queue */# include <cstdio> # include <iostream> # include <algorithm> # include <queue> using namespace std; const int maxn = 5010; int n; struct Node {int l, r, id; friend bool operator <(const Node & a, const Node & B) {if (. l! = B. l) return. l> B. l; return. r> B. r ;}} arr1 [maxn], arr2 [maxn]; int ans [maxn] [2]; bool check (Node * arr, int pos) {priority_queue <Node> Q; for (int I = 0; I <n; ++ I) Q. push (arr [I]); int maxx = 0; while (! Q. empty () {Node tmp = Q. top (); Q. pop (); if (tmp. r <maxx) return false; if (tmp. l <maxx) {tmp. l = maxx; Q. push (tmp); continue;} int cur = max (maxx, tmp. l); ans [tmp. id] [pos] = cur; maxx = cur + 1;} return true;} int main () {int I, j; while (~ Scanf ("% d", & n) {for (I = 0; I <n; ++ I) {scanf ("% d", & arr1 [I]. l, & arr2 [I]. l, & arr1 [I]. r, & arr2 [I]. r); arr1 [I]. id = arr2 [I]. id = I;} if (check (arr1, 0) & check (arr2, 1) {for (I = 0; I <n; ++ I) printf ("% d \ n", ans [I] [0], ans [I] [1]);} else {puts ("IMPOSSIBLE ");}} return 0 ;}