#include <vector> #include <cstdio> using namespace std; int t; struct Desc { int w1, w2, h1, h2; }; bool solve(const vector<Desc>& data) { Desc max_desc = data[0]; for(unsigned int i=1; i<data.size(); ++i) { max_desc.w1 = min(max_desc.w1, data[i].w1); max_desc.w2 = max(max_desc.w2, data[i].w2); max_desc.h1 = min(max_desc.h1, data[i].h1); max_desc.h2 = max(max_desc.h2, data[i].h2); } for(unsigned int i=0; i<data.size(); ++i) { if(data[i].w1==max_desc.w1 && data[i].w2==max_desc.w2 && data[i].h1==max_desc.h1 && data[i].h2==max_desc.h2 ) return true; } return false; } int main() { scanf(" %d", &t); for(int i=0; i<t; ++i) { int n; scanf(" %d", &n); vector<Desc> oferty; oferty.reserve(n); for(int j=0; j<n; ++j) { Desc d; scanf(" %d %d %d %d", &d.w1, &d.w2, &d.h1, &d.h2); oferty.push_back(d); } if( solve(oferty) ) printf("TAK"); else printf("NIE"); if(i!=t-1) printf("\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 | #include <vector> #include <cstdio> using namespace std; int t; struct Desc { int w1, w2, h1, h2; }; bool solve(const vector<Desc>& data) { Desc max_desc = data[0]; for(unsigned int i=1; i<data.size(); ++i) { max_desc.w1 = min(max_desc.w1, data[i].w1); max_desc.w2 = max(max_desc.w2, data[i].w2); max_desc.h1 = min(max_desc.h1, data[i].h1); max_desc.h2 = max(max_desc.h2, data[i].h2); } for(unsigned int i=0; i<data.size(); ++i) { if(data[i].w1==max_desc.w1 && data[i].w2==max_desc.w2 && data[i].h1==max_desc.h1 && data[i].h2==max_desc.h2 ) return true; } return false; } int main() { scanf(" %d", &t); for(int i=0; i<t; ++i) { int n; scanf(" %d", &n); vector<Desc> oferty; oferty.reserve(n); for(int j=0; j<n; ++j) { Desc d; scanf(" %d %d %d %d", &d.w1, &d.w2, &d.h1, &d.h2); oferty.push_back(d); } if( solve(oferty) ) printf("TAK"); else printf("NIE"); if(i!=t-1) printf("\n"); } return 0; } |