#include <cstdio> #include <algorithm> #include <utility> #include <vector> static const unsigned int MAX_TEST_CASES = 10; static const unsigned int MAX_FACTORIES = 100 * 1000; struct rect { int width, height; static inline rect bound(const rect & r1, const rect & r2) { return { std::max(r1.width, r2.width), std::max(r1.height, r2.height) }; } static inline rect kernel(const rect & r1, const rect & r2) { return { std::min(r1.width, r2.width), std::min(r1.height, r2.height) }; } inline void print() const { printf("{ %d, %d }", width, height); } }; inline rect operator|(const rect & r1, const rect & r2) { return rect::bound(r1, r2); } inline rect operator&(const rect & r1, const rect & r2) { return rect::kernel(r1, r2); } bool operator==(const rect & r1, const rect & r2) { return (r1.width == r2.width) && (r1.height == r2.height); } struct factory { rect lower, upper; inline void print() const { printf("{ "); lower.print(); printf(", "); upper.print(); printf(" }"); } }; bool operator==(const factory & f1, const factory & f2) { return (f1.lower == f2.lower) && (f1.upper == f2.upper); } inline int nextInt() { int i; scanf("%d", &i); return i; } inline void loadInts() {} template<typename... Args> inline void loadInts(int & i, Args&... args) { i = nextInt(); //printf("%p (%d)\n", &i, i); loadInts(args...); } inline void doTest() { int n; int w1, w2, h1, h2; //printf("%p, %p, %p, %p\n", &w1, &w2, &h1, &h2); std::vector<factory> factories; n = nextInt(); factories.reserve(n); for (int i = 0; i < n; i++) { loadInts(w1, w2, h1, h2); //printf("%d, %d, %d, %d\n", w1, w2, h1, h2); factories.push_back( factory { { w1, h1 }, { w2, h2 } } ); } factory modelFactory = factories[0]; for (factory & f : factories) modelFactory = { modelFactory.lower & f.lower, modelFactory.upper | f.upper }; //modelFactory.print(); //puts(""); bool majorizes = (std::find(factories.begin(), factories.end(), modelFactory) != factories.end()); puts(majorizes ? "TAK" : "NIE"); } int main() { int t = nextInt(); while (t --> 0) doTest(); return 0; }
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #include <cstdio> #include <algorithm> #include <utility> #include <vector> static const unsigned int MAX_TEST_CASES = 10; static const unsigned int MAX_FACTORIES = 100 * 1000; struct rect { int width, height; static inline rect bound(const rect & r1, const rect & r2) { return { std::max(r1.width, r2.width), std::max(r1.height, r2.height) }; } static inline rect kernel(const rect & r1, const rect & r2) { return { std::min(r1.width, r2.width), std::min(r1.height, r2.height) }; } inline void print() const { printf("{ %d, %d }", width, height); } }; inline rect operator|(const rect & r1, const rect & r2) { return rect::bound(r1, r2); } inline rect operator&(const rect & r1, const rect & r2) { return rect::kernel(r1, r2); } bool operator==(const rect & r1, const rect & r2) { return (r1.width == r2.width) && (r1.height == r2.height); } struct factory { rect lower, upper; inline void print() const { printf("{ "); lower.print(); printf(", "); upper.print(); printf(" }"); } }; bool operator==(const factory & f1, const factory & f2) { return (f1.lower == f2.lower) && (f1.upper == f2.upper); } inline int nextInt() { int i; scanf("%d", &i); return i; } inline void loadInts() {} template<typename... Args> inline void loadInts(int & i, Args&... args) { i = nextInt(); //printf("%p (%d)\n", &i, i); loadInts(args...); } inline void doTest() { int n; int w1, w2, h1, h2; //printf("%p, %p, %p, %p\n", &w1, &w2, &h1, &h2); std::vector<factory> factories; n = nextInt(); factories.reserve(n); for (int i = 0; i < n; i++) { loadInts(w1, w2, h1, h2); //printf("%d, %d, %d, %d\n", w1, w2, h1, h2); factories.push_back( factory { { w1, h1 }, { w2, h2 } } ); } factory modelFactory = factories[0]; for (factory & f : factories) modelFactory = { modelFactory.lower & f.lower, modelFactory.upper | f.upper }; //modelFactory.print(); //puts(""); bool majorizes = (std::find(factories.begin(), factories.end(), modelFactory) != factories.end()); puts(majorizes ? "TAK" : "NIE"); } int main() { int t = nextInt(); while (t --> 0) doTest(); return 0; } |