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 91 92 93 94 95 96 97 98 99 100 101 102 103 #include #include // Helper definition #define VAR(v, i) __typeof(i) v=(i) #define FOR(i, j, k) for (int i = (j); i <= (k); ++i) #define FORD(i, j, k)for (int i=(j); i >= (k); --i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define REP(i, n) for(int i = 0;i <(n); ++i) #define TRUE "TAK" #define FALSE "NIE" /** Structure that define one offer by the store */ struct offer { unsigned int w1; unsigned int w2; unsigned int h1; unsigned int h2; void operator=(const int value); void operator=(const offer &r); }; inline void offer::operator=(const int value) { w1 = value; w2 = value; h1 = value; h2 = value; } inline void offer::operator=(const offer &r) { w1 = r.w1; w2 = r.w2; h1 = r.h1; h2 = r.h2; } inline bool operator==(const offer &l, const offer &r) { return l.w1 == r.w1 && l.w2 == r.w2 && l.h1 == r.h1 && l.h2 == r.h2; } inline void operator+=(offer &l, const offer &r) { if (l.w1 > r.w1) l.w1 = r.w1; if (l.w2 < r.w2) l.w2 = r.w2; if (l.h1 > r.h1) l.h1 = r.h1; if (l.h2 < r.h2) l.h2 = r.h2; } inline void operator*=(offer &l, const offer &r) { if (l.w1 >= r.w1 && l.w2 <= r.w2 && l.h1 >= r.h1 && l.h2 <= r.h2) l = r; } int main(int argc, char **argv) { unsigned int test; unsigned int offers; offer cover; offer best; offer temp; scanf("%d", &test); REP(i, test) { // Reset variable cover = 0; best = 0; // Read number of offers scanf("%d", &offers); scanf("%d %d %d %d", &best.w1, &best.w2, &best.h1, &best.h2); cover = best; REP(j, offers - 1) { scanf("%d %d %d %d", &temp.w1, &temp.w2, &temp.h1, &temp.h2); best += temp; cover*= temp; } if (cover == best) printf("%s\n", TRUE); else printf("%s\n", FALSE); } return 0; }