#include <iostream> #include <cstdio> #include <set> #include <vector> #include <algorithm> #include <map> #include <cmath> #include <climits> using namespace std; //#define LONG long long //#define LONG __int64 void Solve() { set<long> SminX, SmaxX, SminY, SmaxY; long minX = LONG_MAX, maxX = LONG_MIN, minY = LONG_MAX, maxY = LONG_MIN; long MminX = LONG_MAX, MmaxX = LONG_MIN, MminY = LONG_MAX, MmaxY = LONG_MIN; long factories = 0L; scanf("%ld\n", &factories); for(long idx = 1; idx <= factories; ++idx) { scanf("%ld %ld %ld %ld\n", &MminX, &MmaxX, &MminY, &MmaxY); if(MminX < minX) { SminX.clear(); SminX.insert(idx); minX = MminX; } else if (MminX == minX) SminX.insert(idx); if(MminY < minY) { SminY.clear(); SminY.insert(idx); minY = MminY; } else if (MminY == minY) SminY.insert(idx); if(MmaxX > maxX) { SmaxX.clear(); SmaxX.insert(idx); maxX = MmaxX; } else if (MmaxX == maxX) SmaxX.insert(idx); if(MmaxY > maxY) { SmaxY.clear(); SmaxY.insert(idx); maxY = MmaxY; } else if (MmaxY == maxY) SmaxY.insert(idx); } std::vector<int> Vres1; std::set_intersection(SminX.begin(), SminX.end(), SmaxX.begin(), SmaxX.end(), std::back_inserter(Vres1)); if(Vres1.size() > 0) { sort(Vres1.begin(), Vres1.end()); std::vector<int> Vres2; std::set_intersection(SminY.begin(), SminY.end(), Vres1.begin(), Vres1.end(), std::back_inserter(Vres2)); if(Vres2.size() > 0) { sort(Vres2.begin(), Vres2.end()); std::vector<int> Vres3; std::set_intersection(SmaxY.begin(), SmaxY.end(), Vres2.begin(), Vres2.end(), std::back_inserter(Vres3)); if(Vres3.size() > 0) { printf("TAK\n"); return; } } } printf("NIE\n"); } int main(int argc, char* argv[]) { long examples = 0; scanf("%ld\n", &examples); for(long idx = 1; idx <= examples; ++idx) Solve(); 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 | #include <iostream> #include <cstdio> #include <set> #include <vector> #include <algorithm> #include <map> #include <cmath> #include <climits> using namespace std; //#define LONG long long //#define LONG __int64 void Solve() { set<long> SminX, SmaxX, SminY, SmaxY; long minX = LONG_MAX, maxX = LONG_MIN, minY = LONG_MAX, maxY = LONG_MIN; long MminX = LONG_MAX, MmaxX = LONG_MIN, MminY = LONG_MAX, MmaxY = LONG_MIN; long factories = 0L; scanf("%ld\n", &factories); for(long idx = 1; idx <= factories; ++idx) { scanf("%ld %ld %ld %ld\n", &MminX, &MmaxX, &MminY, &MmaxY); if(MminX < minX) { SminX.clear(); SminX.insert(idx); minX = MminX; } else if (MminX == minX) SminX.insert(idx); if(MminY < minY) { SminY.clear(); SminY.insert(idx); minY = MminY; } else if (MminY == minY) SminY.insert(idx); if(MmaxX > maxX) { SmaxX.clear(); SmaxX.insert(idx); maxX = MmaxX; } else if (MmaxX == maxX) SmaxX.insert(idx); if(MmaxY > maxY) { SmaxY.clear(); SmaxY.insert(idx); maxY = MmaxY; } else if (MmaxY == maxY) SmaxY.insert(idx); } std::vector<int> Vres1; std::set_intersection(SminX.begin(), SminX.end(), SmaxX.begin(), SmaxX.end(), std::back_inserter(Vres1)); if(Vres1.size() > 0) { sort(Vres1.begin(), Vres1.end()); std::vector<int> Vres2; std::set_intersection(SminY.begin(), SminY.end(), Vres1.begin(), Vres1.end(), std::back_inserter(Vres2)); if(Vres2.size() > 0) { sort(Vres2.begin(), Vres2.end()); std::vector<int> Vres3; std::set_intersection(SmaxY.begin(), SmaxY.end(), Vres2.begin(), Vres2.end(), std::back_inserter(Vres3)); if(Vres3.size() > 0) { printf("TAK\n"); return; } } } printf("NIE\n"); } int main(int argc, char* argv[]) { long examples = 0; scanf("%ld\n", &examples); for(long idx = 1; idx <= examples; ++idx) Solve(); return 0; } |