1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| // // main.cpp // UVA11134 // // Created by zhangmin chen on 2019/5/19. // Copyright © 2019 zhangmin chen. All rights reserved. //
using namespace std; typedef long long llong; typedef set<string>::iterator ssii;
const int inf = 0x3f3f3f3f; const int maxn = 5000 + 5;
bool inRange(int lo, int hi, int x) { if(lo > hi) return inRange(hi, lo, x); return lo <= x && x <= hi; }
int xl[maxn], xr[maxn], yl[maxn], yr[maxn]; int x[maxn], y[maxn];
void init() { Set(xl, 0); Set(xr, 0); Set(yl, 0); Set(yr, 0); Set(x, 0); Set(y, 0); }
bool solve(int* l, int* r, int* res, int n) { fill(res, res+n, -1); _rep(val, 1, n) { int p = -1, minr = n+1; // choose min interval for each val _for(i, 0, n) { if(val >= l[i]) { if(res[i] < 0 && r[i] < minr) { minr = r[i]; p = i; } } } if(val > minr || p < 0) return false; res[p] = val; } return true; }
int n;
int main() { //freopen("input.txt", "r", stdin); while (scanf("%d", &n) == 1 && n) { init(); _for(i, 0, n) cin >> xl[i] >> yl[i] >> xr[i] >> yr[i]; // then solve() if(solve(xl, xr, x, n) && solve(yl, yr, y, n)) _for(i, 0, n) printf("%d %d\n", x[i], y[i]); else printf("IMPOSSIBLE\n"); // while finished } }
|