#include <cstdio>
#include <cstdlib>
#include <iostream>
class Mirror
{
public:
bool operator> (const Mirror& other) const
{
return w1<=other.w1 && w2>=other.w2 && h1<=other.h1 && h2>=other.h2;
}
Mirror& operator&= (const Mirror& other)
{
w1 = std::min(w1, other.w1);
w2 = std::max(w2, other.w2);
h1 = std::min(h1, other.h1);
h2 = std::max(h2, other.h2);
return *this;
}
friend std::ostream& operator<< (std::ostream& os, const Mirror& m)
{
return os << "Mirror(" << m.w1 << "-" << m.w2 << "; " << m.h1 << "-" << m.h2 << ")";
}
friend std::istream& operator>> (std::istream& is, Mirror& m)
{
return is >> m.w1 >> m.w2 >> m.h1 >> m.h2;
}
private:
int w1, w2;
int h1, h2;
};
int main()
{
std::ios_base::sync_with_stdio(0);
int t;
std::cin >> t;
while (t--)
{
int n;
Mirror base;
std::cin >> n >> base;
bool ok = true;
while (--n)
{
Mirror mirror;
std::cin >> mirror;
ok = (mirror>base) || (ok && (base>mirror));
base &= mirror;
}
std::cout << (ok ? "TAK" : "NIE") << std::endl;
}
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 | #include <cstdio> #include <cstdlib> #include <iostream> class Mirror { public: bool operator> (const Mirror& other) const { return w1<=other.w1 && w2>=other.w2 && h1<=other.h1 && h2>=other.h2; } Mirror& operator&= (const Mirror& other) { w1 = std::min(w1, other.w1); w2 = std::max(w2, other.w2); h1 = std::min(h1, other.h1); h2 = std::max(h2, other.h2); return *this; } friend std::ostream& operator<< (std::ostream& os, const Mirror& m) { return os << "Mirror(" << m.w1 << "-" << m.w2 << "; " << m.h1 << "-" << m.h2 << ")"; } friend std::istream& operator>> (std::istream& is, Mirror& m) { return is >> m.w1 >> m.w2 >> m.h1 >> m.h2; } private: int w1, w2; int h1, h2; }; int main() { std::ios_base::sync_with_stdio(0); int t; std::cin >> t; while (t--) { int n; Mirror base; std::cin >> n >> base; bool ok = true; while (--n) { Mirror mirror; std::cin >> mirror; ok = (mirror>base) || (ok && (base>mirror)); base &= mirror; } std::cout << (ok ? "TAK" : "NIE") << std::endl; } return 0; } |
English