#include <iostream> #include <set> using namespace std; // class Factory // { // public: // int id; // Point w; // Point h; // Factory(int id, Point a, Point b) : id(id), w(a), h(b){ // } // }; // class FactoryMajorTestW // { // public: // int operator()(Factory a, Factory b){ // if(a.w.x <= b.w.x && a.w.y >= b.w.y){ // return 1; // } // return 0; // } // }; // class FactoryMajorTestH // { // public: // int operator()(Factory a, Factory b){ // if(a.h.x <= b.h.x && a.h.y >= b.h.y){ // return 1; // } // return 0; // } // }; class Point { public: int factory_id; int x; int y; Point(int id, int a, int b) : factory_id(id), x(a), y(b){ } }; class PointMajor { public: int operator()(const Point &a, const Point &b){ int w_x = b.x - a.x; // > 0 => a lepsze int w_y = a.y - b.y; // > 0 => a lepsze if(w_x > 0 && w_y > 0){ return 2; } else if((w_x > 0 && w_y < 0) || (w_x < 0 && w_y > 0)){ return 0; } else if(w_x == 0 && w_y == 0){ return -1; } else if(w_x < 0 && w_y < 0){ return -2; } return 0; } }; int main() { ios_base::sync_with_stdio(0); int no_tests; cin >> no_tests; while(no_tests > 0){ #ifdef DEBUG cout << "-- Test" << endl; #endif multiset<Point, PointMajor > paretoW; multiset<Point, PointMajor > paretoH; int no_factory; cin >> no_factory; int w1,w2,h1,h2; cin >> w1 >> w2 >> h1 >> h2; paretoW.insert(Point(1, w1, w2)); paretoH.insert(Point(1, h1, h2)); for(int nof=2; nof <= no_factory; nof++){ cin >> w1 >> w2 >> h1 >> h2; Point f_w(nof, w1, w2); Point f_h(nof, h1, h2); #ifdef DEBUG cout << "++++ITER++" << endl; cout << " W:" << paretoW.size() << endl; for(auto &p : paretoW){ cout << " Pw_" << p.factory_id << " = (" << p.x << ", " << p.y << ") " << endl; } cout << "--------------------------------" << endl; #endif auto lowerW = paretoW.lower_bound(f_w); paretoW.erase(lowerW, paretoW.end()); paretoW.insert(f_w); auto lowerH = paretoH.lower_bound(f_h); paretoH.erase(lowerH, paretoH.end()); paretoH.insert(f_h); #ifdef DEBUG cout << "Pw_" << nof << "(" << w1 << ", " << w2 << ")" << endl; // cout << "Pw_" << nof << "(" << w1 << ", " << w2 << ") ->" << (lower == paretoW.begin()) << endl; cout << "++++++++++++++++++++++++" << endl; #endif } #ifdef DEBUG cout << " W:" << paretoW.size() << endl; for(auto &p : paretoW){ cout << " Pw_" << p.factory_id << " = (" << p.x << ", " << p.y << ") " << endl; } cout << " H:" << paretoH.size() << endl; for(auto &p : paretoH){ cout << " Ph_" << p.factory_id << " = (" << p.x << ", " << p.y << ") " << endl; } #endif // decision // auto ph_beg = paretoH.begin(); // auto ph_beg_2 = ph_beg++; // auto pw_beg = paretoW.begin(); // auto pw_beg_2 = pw_beg++; /* if(paretoH.size() > 1 || paretoW.size() > 1){ cout << "NIE" << endl; } // else if( (paretoH.size() == 1 && ((*ph_beg).factory_id != (*ph_beg_2).factory_id)) || (paretoW.size() == 1 && ((*pw_beg).factory_id != (*pw_beg_2).factory_id))){ // cout << "NIE" << endl; // } else{ cout << "TAK" << endl; } */ if(paretoH.size() == 1 && paretoW.size() == 1){ cout << "TAK" << endl; } // else if( (paretoH.size() == 1 && ((*ph_beg).factory_id != (*ph_beg_2).factory_id)) || (paretoW.size() == 1 && ((*pw_beg).factory_id != (*pw_beg_2).factory_id))){ // cout << "NIE" << endl; // } else{ cout << "NIE" << endl; } no_tests--; } 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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | #include <iostream> #include <set> using namespace std; // class Factory // { // public: // int id; // Point w; // Point h; // Factory(int id, Point a, Point b) : id(id), w(a), h(b){ // } // }; // class FactoryMajorTestW // { // public: // int operator()(Factory a, Factory b){ // if(a.w.x <= b.w.x && a.w.y >= b.w.y){ // return 1; // } // return 0; // } // }; // class FactoryMajorTestH // { // public: // int operator()(Factory a, Factory b){ // if(a.h.x <= b.h.x && a.h.y >= b.h.y){ // return 1; // } // return 0; // } // }; class Point { public: int factory_id; int x; int y; Point(int id, int a, int b) : factory_id(id), x(a), y(b){ } }; class PointMajor { public: int operator()(const Point &a, const Point &b){ int w_x = b.x - a.x; // > 0 => a lepsze int w_y = a.y - b.y; // > 0 => a lepsze if(w_x > 0 && w_y > 0){ return 2; } else if((w_x > 0 && w_y < 0) || (w_x < 0 && w_y > 0)){ return 0; } else if(w_x == 0 && w_y == 0){ return -1; } else if(w_x < 0 && w_y < 0){ return -2; } return 0; } }; int main() { ios_base::sync_with_stdio(0); int no_tests; cin >> no_tests; while(no_tests > 0){ #ifdef DEBUG cout << "-- Test" << endl; #endif multiset<Point, PointMajor > paretoW; multiset<Point, PointMajor > paretoH; int no_factory; cin >> no_factory; int w1,w2,h1,h2; cin >> w1 >> w2 >> h1 >> h2; paretoW.insert(Point(1, w1, w2)); paretoH.insert(Point(1, h1, h2)); for(int nof=2; nof <= no_factory; nof++){ cin >> w1 >> w2 >> h1 >> h2; Point f_w(nof, w1, w2); Point f_h(nof, h1, h2); #ifdef DEBUG cout << "++++ITER++" << endl; cout << " W:" << paretoW.size() << endl; for(auto &p : paretoW){ cout << " Pw_" << p.factory_id << " = (" << p.x << ", " << p.y << ") " << endl; } cout << "--------------------------------" << endl; #endif auto lowerW = paretoW.lower_bound(f_w); paretoW.erase(lowerW, paretoW.end()); paretoW.insert(f_w); auto lowerH = paretoH.lower_bound(f_h); paretoH.erase(lowerH, paretoH.end()); paretoH.insert(f_h); #ifdef DEBUG cout << "Pw_" << nof << "(" << w1 << ", " << w2 << ")" << endl; // cout << "Pw_" << nof << "(" << w1 << ", " << w2 << ") ->" << (lower == paretoW.begin()) << endl; cout << "++++++++++++++++++++++++" << endl; #endif } #ifdef DEBUG cout << " W:" << paretoW.size() << endl; for(auto &p : paretoW){ cout << " Pw_" << p.factory_id << " = (" << p.x << ", " << p.y << ") " << endl; } cout << " H:" << paretoH.size() << endl; for(auto &p : paretoH){ cout << " Ph_" << p.factory_id << " = (" << p.x << ", " << p.y << ") " << endl; } #endif // decision // auto ph_beg = paretoH.begin(); // auto ph_beg_2 = ph_beg++; // auto pw_beg = paretoW.begin(); // auto pw_beg_2 = pw_beg++; /* if(paretoH.size() > 1 || paretoW.size() > 1){ cout << "NIE" << endl; } // else if( (paretoH.size() == 1 && ((*ph_beg).factory_id != (*ph_beg_2).factory_id)) || (paretoW.size() == 1 && ((*pw_beg).factory_id != (*pw_beg_2).factory_id))){ // cout << "NIE" << endl; // } else{ cout << "TAK" << endl; } */ if(paretoH.size() == 1 && paretoW.size() == 1){ cout << "TAK" << endl; } // else if( (paretoH.size() == 1 && ((*ph_beg).factory_id != (*ph_beg_2).factory_id)) || (paretoW.size() == 1 && ((*pw_beg).factory_id != (*pw_beg_2).factory_id))){ // cout << "NIE" << endl; // } else{ cout << "NIE" << endl; } no_tests--; } return 0; } |