#include <algorithm> #include <cassert> #include <iostream> #include <vector> using namespace std; #define REP(i,n) for(int _n=n, i=0;i<_n;++i) class Input { public: Input() { bufpos = bufend = buffer; eof = false; } bool Eof() { return eof; } char Peek() { if(bufpos == bufend) Grab(); return *bufpos; } unsigned char UPeek() { return static_cast<unsigned char>(Peek()); } void SkipWS(); template<class T> T Get(); void operator()() {} template<class Arg, class... Args> void operator()(Arg &arg, Args &... args) { arg = Get<Arg>(); operator()(args...); } private: static const int BUFSIZE = 1<<16; char buffer[BUFSIZE]; char *bufpos; char *bufend; bool eof; void Grab(); }; void Input::Grab() { if(eof) return; bufpos = buffer; bufend = buffer + read(0, buffer, BUFSIZE); if(bufend==bufpos) { eof=true; *bufpos=0; } } template<> inline char Input::Get<char>() { char res = Peek(); ++bufpos; return res; } void inline Input::SkipWS() { while(isspace(UPeek())) Get<char>(); } template<> inline unsigned Input::Get<unsigned>() { SkipWS(); unsigned x = 0; while(isdigit(UPeek())) { x = 10u * x + (Get<char>()-'0'); } return x; } template<> inline int Input::Get<int>() { return static_cast<int>(Get<unsigned>()); } Input IN; struct Zaklad { int w1,w2,h1,h2; }; vector<Zaklad> zaklady; void ReadInput() { int n; IN(n); zaklady.clear(); zaklady.reserve(n); REP(i,n) { Zaklad z; IN(z.w1,z.w2,z.h1,z.h2); zaklady.push_back(z); } } const Zaklad *FindLargest() { const Zaklad *best = nullptr; int bestV = -1; for (const Zaklad &z : zaklady) { int v = z.w2-z.w1 + z.h2 - z.h1; if(v>bestV) { bestV = v; best = &z; } } assert(best); return best; } bool Solve() { const Zaklad *largest = FindLargest(); for (const Zaklad &z : zaklady) { if (z.w1 < largest->w1 || z.w2 > largest->w2 || z.h1 < largest->h1 || z.h2 > largest->h2) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int ntc; IN(ntc); REP(tc,ntc) { ReadInput(); bool res = Solve(); cout << (res ? "TAK\n" : "NIE\n"); } }
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 | #include <algorithm> #include <cassert> #include <iostream> #include <vector> using namespace std; #define REP(i,n) for(int _n=n, i=0;i<_n;++i) class Input { public: Input() { bufpos = bufend = buffer; eof = false; } bool Eof() { return eof; } char Peek() { if(bufpos == bufend) Grab(); return *bufpos; } unsigned char UPeek() { return static_cast<unsigned char>(Peek()); } void SkipWS(); template<class T> T Get(); void operator()() {} template<class Arg, class... Args> void operator()(Arg &arg, Args &... args) { arg = Get<Arg>(); operator()(args...); } private: static const int BUFSIZE = 1<<16; char buffer[BUFSIZE]; char *bufpos; char *bufend; bool eof; void Grab(); }; void Input::Grab() { if(eof) return; bufpos = buffer; bufend = buffer + read(0, buffer, BUFSIZE); if(bufend==bufpos) { eof=true; *bufpos=0; } } template<> inline char Input::Get<char>() { char res = Peek(); ++bufpos; return res; } void inline Input::SkipWS() { while(isspace(UPeek())) Get<char>(); } template<> inline unsigned Input::Get<unsigned>() { SkipWS(); unsigned x = 0; while(isdigit(UPeek())) { x = 10u * x + (Get<char>()-'0'); } return x; } template<> inline int Input::Get<int>() { return static_cast<int>(Get<unsigned>()); } Input IN; struct Zaklad { int w1,w2,h1,h2; }; vector<Zaklad> zaklady; void ReadInput() { int n; IN(n); zaklady.clear(); zaklady.reserve(n); REP(i,n) { Zaklad z; IN(z.w1,z.w2,z.h1,z.h2); zaklady.push_back(z); } } const Zaklad *FindLargest() { const Zaklad *best = nullptr; int bestV = -1; for (const Zaklad &z : zaklady) { int v = z.w2-z.w1 + z.h2 - z.h1; if(v>bestV) { bestV = v; best = &z; } } assert(best); return best; } bool Solve() { const Zaklad *largest = FindLargest(); for (const Zaklad &z : zaklady) { if (z.w1 < largest->w1 || z.w2 > largest->w2 || z.h1 < largest->h1 || z.h2 > largest->h2) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int ntc; IN(ntc); REP(tc,ntc) { ReadInput(); bool res = Solve(); cout << (res ? "TAK\n" : "NIE\n"); } } |