#include <iostream> #include <algorithm> #include <cstdio> #include <vector> using namespace std; struct rect { int x1,y1,x2,y2; }; void normalize(rect &r) { if(r.x1 > r.x2) swap(r.x1, r.x2); if(r.y1 > r.y2) swap(r.y1, r.y2); } bool overlap_intervals(rect &r, int a, int b) { return (b > r.x1 && a < r.x2); } bool check(vector<rect> &in, vector<rect> &out, int w) { int a,b,d1,d2; int n = in.size(); for(int i=0; i<n; i++) { d1 = in[i].y2 - in[i].y1; if(in[i].x1 >= out[i].x1) { a = out[i].x1; b = in[i].x1; } else { a = in[i].x1; b = out[i].x2; } for(int j=0; j<n; j++) { if(i!=j && overlap_intervals(in[j], a, b)) { d2 = in[j].y2 - in[j].y1; if(d1 + d2 > w) return false; } } } return true; } int main(int argc, char *argv[]) { int t,n,w; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &w); vector<rect> in,out; rect r; for(int i=0; i<n; i++) { scanf("%d%d%d%d", &r.x1, &r.y1, &r.x2, &r.y2); normalize(r); in.push_back(r); } for(int i=0; i<n; i++) { scanf("%d%d%d%d", &r.x1, &r.y1, &r.x2, &r.y2); normalize(r); out.push_back(r); } if(check(in, out, w)) puts("TAK"); else puts("NIE"); } 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 | #include <iostream> #include <algorithm> #include <cstdio> #include <vector> using namespace std; struct rect { int x1,y1,x2,y2; }; void normalize(rect &r) { if(r.x1 > r.x2) swap(r.x1, r.x2); if(r.y1 > r.y2) swap(r.y1, r.y2); } bool overlap_intervals(rect &r, int a, int b) { return (b > r.x1 && a < r.x2); } bool check(vector<rect> &in, vector<rect> &out, int w) { int a,b,d1,d2; int n = in.size(); for(int i=0; i<n; i++) { d1 = in[i].y2 - in[i].y1; if(in[i].x1 >= out[i].x1) { a = out[i].x1; b = in[i].x1; } else { a = in[i].x1; b = out[i].x2; } for(int j=0; j<n; j++) { if(i!=j && overlap_intervals(in[j], a, b)) { d2 = in[j].y2 - in[j].y1; if(d1 + d2 > w) return false; } } } return true; } int main(int argc, char *argv[]) { int t,n,w; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &w); vector<rect> in,out; rect r; for(int i=0; i<n; i++) { scanf("%d%d%d%d", &r.x1, &r.y1, &r.x2, &r.y2); normalize(r); in.push_back(r); } for(int i=0; i<n; i++) { scanf("%d%d%d%d", &r.x1, &r.y1, &r.x2, &r.y2); normalize(r); out.push_back(r); } if(check(in, out, w)) puts("TAK"); else puts("NIE"); } return 0; } |