#include <iostream> #define POTENTIAL(w1, w2, h1, h2, w_min, w_max, h_min, h_max) \ (w1 > w_min || w2 < w_max || h1 > h_min || h2 < h_max) using namespace std; int main () { cin.sync_with_stdio(false); int t, n; int w1, w2, h1, h2; int w_min, w_max, h_min, h_max; bool changed; bool potential; cin >> t; for (int i = 0; i < t; ++i) { bool isMajorant = true; //First row values are boundaries. cin >> n >> w_min >> w_max >> h_min >> h_max; //Next iterations for (int j = 1; j < n; ++j) { cin >> w1 >> w2 >> h1 >> h2; potential = !POTENTIAL(w1, w2, h1, h2, w_min, w_max, h_min, h_max); changed = POTENTIAL(w2, w1, h2, h1, w_max, w_min, h_max, h_min); w_min = min(w1, w_min); w_max = max(w2, w_max); h_min = min(h1, h_min); h_max = max(h2, h_max); if (changed) { isMajorant = potential; } else if (potential) { isMajorant = true; } } cout << (isMajorant ? "TAK" : "NIE") << 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 | #include <iostream> #define POTENTIAL(w1, w2, h1, h2, w_min, w_max, h_min, h_max) \ (w1 > w_min || w2 < w_max || h1 > h_min || h2 < h_max) using namespace std; int main () { cin.sync_with_stdio(false); int t, n; int w1, w2, h1, h2; int w_min, w_max, h_min, h_max; bool changed; bool potential; cin >> t; for (int i = 0; i < t; ++i) { bool isMajorant = true; //First row values are boundaries. cin >> n >> w_min >> w_max >> h_min >> h_max; //Next iterations for (int j = 1; j < n; ++j) { cin >> w1 >> w2 >> h1 >> h2; potential = !POTENTIAL(w1, w2, h1, h2, w_min, w_max, h_min, h_max); changed = POTENTIAL(w2, w1, h2, h1, w_max, w_min, h_max, h_min); w_min = min(w1, w_min); w_max = max(w2, w_max); h_min = min(h1, h_min); h_max = max(h2, h_max); if (changed) { isMajorant = potential; } else if (potential) { isMajorant = true; } } cout << (isMajorant ? "TAK" : "NIE") << endl; } return 0; } |