#include "stdio.h"
#include <algorithm>
using namespace std;
struct rect {
int w1,w2,h1,h2;
rect& operator=(const rect& a) {
w1=a.w1;
w2=a.w2;
h1=a.h1;
h2=a.h2;
return *this;
}
};
bool covers(rect r1,rect r2) {
return (r1.w1 <= r2.w1 && r1.w2 >= r2.w2 && r1.h1 <= r2.h1 && r1.h2 >= r2.h2);
}
rect coverage(rect r1, rect r2) {
rect result;
result.w1=min(r1.w1,r2.w1);
result.w2=max(r1.w2,r2.w2);
result.h1=min(r1.h1,r2.h1);
result.h2=max(r1.h2,r2.h2);
return result;
}
int main()
{
int t;
scanf("%d",&t);
int n; rect cov, max;
for( int i=0; i<t; ++i) {
scanf("%d",&n);
rect r;
scanf("%d%d%d%d",&r.w1,&r.w2,&r.h1,&r.h2);
cov = r; max=r;
for(int j=0; j<n-1; ++j) {
scanf("%d%d%d%d",&r.w1,&r.w2,&r.h1,&r.h2);
max=coverage(max,r);
if(covers(r,max)) cov=r;
}
if(covers(cov,max)) printf("TAK\n");
else printf("NIE\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 | #include "stdio.h" #include <algorithm> using namespace std; struct rect { int w1,w2,h1,h2; rect& operator=(const rect& a) { w1=a.w1; w2=a.w2; h1=a.h1; h2=a.h2; return *this; } }; bool covers(rect r1,rect r2) { return (r1.w1 <= r2.w1 && r1.w2 >= r2.w2 && r1.h1 <= r2.h1 && r1.h2 >= r2.h2); } rect coverage(rect r1, rect r2) { rect result; result.w1=min(r1.w1,r2.w1); result.w2=max(r1.w2,r2.w2); result.h1=min(r1.h1,r2.h1); result.h2=max(r1.h2,r2.h2); return result; } int main() { int t; scanf("%d",&t); int n; rect cov, max; for( int i=0; i<t; ++i) { scanf("%d",&n); rect r; scanf("%d%d%d%d",&r.w1,&r.w2,&r.h1,&r.h2); cov = r; max=r; for(int j=0; j<n-1; ++j) { scanf("%d%d%d%d",&r.w1,&r.w2,&r.h1,&r.h2); max=coverage(max,r); if(covers(r,max)) cov=r; } if(covers(cov,max)) printf("TAK\n"); else printf("NIE\n"); } return 0; } |
English