#include <iostream>
#include <algorithm>
using namespace std;
struct Producer {
unsigned w1, w2, h1, h2;
bool real;
bool operator >(const Producer &other) {
return w1 <= other.w1
&& w2 >= other.w2
&& h1 <= other.h1
&& h2 >= other.h2;
}
static Producer combine(const Producer &a, const Producer &b) {
return {
min(a.w1, b.w1),
max(a.w2, b.w2),
min(a.h1, b.h1),
max(a.h2, b.h2),
false
};
}
};
istream &operator >>(istream &ins, Producer &p) {
p.real = true;
return ins >> p.w1 >> p.w2 >> p.h1 >> p.h2;
}
int main() {
ios_base::sync_with_stdio(false);
unsigned test_cases;
cin >> test_cases;
while (test_cases--) {
unsigned producers_count;
Producer major;
cin >> producers_count;
cin >> major;
producers_count -= 1;
while (producers_count--) {
Producer current;
cin >> current;
if (current > major) {
major = current;
} else if (major > current) {
continue;
} else {
major = Producer::combine(major, current);
}
}
if (!major.real) {
cout << "NIE\n";
} else {
cout << "TAK\n";
}
}
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 | #include <iostream> #include <algorithm> using namespace std; struct Producer { unsigned w1, w2, h1, h2; bool real; bool operator >(const Producer &other) { return w1 <= other.w1 && w2 >= other.w2 && h1 <= other.h1 && h2 >= other.h2; } static Producer combine(const Producer &a, const Producer &b) { return { min(a.w1, b.w1), max(a.w2, b.w2), min(a.h1, b.h1), max(a.h2, b.h2), false }; } }; istream &operator >>(istream &ins, Producer &p) { p.real = true; return ins >> p.w1 >> p.w2 >> p.h1 >> p.h2; } int main() { ios_base::sync_with_stdio(false); unsigned test_cases; cin >> test_cases; while (test_cases--) { unsigned producers_count; Producer major; cin >> producers_count; cin >> major; producers_count -= 1; while (producers_count--) { Producer current; cin >> current; if (current > major) { major = current; } else if (major > current) { continue; } else { major = Producer::combine(major, current); } } if (!major.real) { cout << "NIE\n"; } else { cout << "TAK\n"; } } return 0; } |
English