#include<iostream> #include<vector> #include<algorithm> #include<cmath> #define ll long long struct Mirror { ll minWidth, maxWidth, minHeight, maxHeight; }; int main(int argc, char** argv) { std::ios_base::sync_with_stdio(false); int tests; std::cin>>tests; while(tests--) { int N; std::cin>>N; Mirror target; std::vector<int> vminw, vmaxw, vminh, vmaxh; for(int i = 0; i < N; ++i) { Mirror mirror; std::cin>>mirror.minWidth>>mirror.maxWidth>>mirror.minHeight>>mirror.maxHeight; if(i == 0) { target = mirror; vminw.push_back(i); vmaxw.push_back(i); vminh.push_back(i); vmaxh.push_back(i); } else { if(mirror.minWidth == target.minWidth) { vminw.push_back(i); } else if(mirror.minWidth < target.minWidth) { vminw.clear(); vminw.push_back(i); target.minWidth = mirror.minWidth; } if(mirror.maxWidth == target.maxWidth) { vmaxw.push_back(i); } else if(mirror.maxWidth > target.maxWidth) { vmaxw.clear(); vmaxw.push_back(i); target.maxWidth = mirror.maxWidth; } if(mirror.minHeight == target.minHeight) { vminh.push_back(i); } else if(mirror.minHeight < target.minHeight) { vminh.clear(); vminh.push_back(i); target.minHeight = mirror.minHeight; } if(mirror.maxHeight == target.maxHeight) { vmaxh.push_back(i); } else if(mirror.maxHeight > target.maxHeight) { vmaxh.clear(); vmaxh.push_back(i); target.maxHeight = mirror.maxHeight; } } } std::vector<int> v1, v2, res; std::set_intersection(vminw.begin(), vminw.end(), vmaxw.begin(), vmaxw.end(), std::back_inserter(v1)); std::set_intersection(v1.begin(), v1.end(), vminh.begin(), vminh.end(), std::back_inserter(v2)); std::set_intersection(v2.begin(), v2.end(), vmaxh.begin(), vmaxh.end(), std::back_inserter(res)); if(res.size() > 0) { std::cout<<"TAK"<<std::endl; } else { std::cout<<"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 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 | #include<iostream> #include<vector> #include<algorithm> #include<cmath> #define ll long long struct Mirror { ll minWidth, maxWidth, minHeight, maxHeight; }; int main(int argc, char** argv) { std::ios_base::sync_with_stdio(false); int tests; std::cin>>tests; while(tests--) { int N; std::cin>>N; Mirror target; std::vector<int> vminw, vmaxw, vminh, vmaxh; for(int i = 0; i < N; ++i) { Mirror mirror; std::cin>>mirror.minWidth>>mirror.maxWidth>>mirror.minHeight>>mirror.maxHeight; if(i == 0) { target = mirror; vminw.push_back(i); vmaxw.push_back(i); vminh.push_back(i); vmaxh.push_back(i); } else { if(mirror.minWidth == target.minWidth) { vminw.push_back(i); } else if(mirror.minWidth < target.minWidth) { vminw.clear(); vminw.push_back(i); target.minWidth = mirror.minWidth; } if(mirror.maxWidth == target.maxWidth) { vmaxw.push_back(i); } else if(mirror.maxWidth > target.maxWidth) { vmaxw.clear(); vmaxw.push_back(i); target.maxWidth = mirror.maxWidth; } if(mirror.minHeight == target.minHeight) { vminh.push_back(i); } else if(mirror.minHeight < target.minHeight) { vminh.clear(); vminh.push_back(i); target.minHeight = mirror.minHeight; } if(mirror.maxHeight == target.maxHeight) { vmaxh.push_back(i); } else if(mirror.maxHeight > target.maxHeight) { vmaxh.clear(); vmaxh.push_back(i); target.maxHeight = mirror.maxHeight; } } } std::vector<int> v1, v2, res; std::set_intersection(vminw.begin(), vminw.end(), vmaxw.begin(), vmaxw.end(), std::back_inserter(v1)); std::set_intersection(v1.begin(), v1.end(), vminh.begin(), vminh.end(), std::back_inserter(v2)); std::set_intersection(v2.begin(), v2.end(), vmaxh.begin(), vmaxh.end(), std::back_inserter(res)); if(res.size() > 0) { std::cout<<"TAK"<<std::endl; } else { std::cout<<"NIE"<<std::endl; } } return 0; } |