#include <cstdio> #include <algorithm> using namespace std; struct samoch{ int x1; int x2; int y1; int y2; int numer; }; bool cmp1(samoch i, samoch j){ return (i.x1<j.x1); } bool cmp2(samoch i, samoch j){ return (i.x2<j.x2); } int main(void){ int jjj; scanf("%d", &jjj); while (jjj--) { int n, w, i; bool jestOK = true; scanf("%d %d", &n, &w); samoch * beg = new samoch [n]; for (i=0; i<n; i++) { scanf("%d %d %d %d", &(beg[i].x1), &(beg[i].y1), &(beg[i].x2), &(beg[i].y2)); beg[i].numer = i; } samoch * end = new samoch [n]; for (i=0; i<n; i++) { scanf("%d %d %d %d", &(end[i].x1), &(end[i].y1), &(end[i].x2), &(end[i].y2)); end[i].numer = i; } sort(beg, beg+n, cmp2); sort(end, end+n, cmp1); int *ind = new int [n]; for (i=0; i<n; i++) ind[beg[i].numer]=i; for (i=0; i<n; i++) { int j = ind[end[i].numer]; for (int k=0; k<j; k++) if (end[i].y2-end[i].y1 + beg[k].y2-beg[k].y1>w) jestOK = false; beg[j].y2 = beg[j].y1; } if (jestOK) printf("TAK\n"); else printf("NIE\n"); delete [] ind; delete [] beg; delete [] end; } 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 | #include <cstdio> #include <algorithm> using namespace std; struct samoch{ int x1; int x2; int y1; int y2; int numer; }; bool cmp1(samoch i, samoch j){ return (i.x1<j.x1); } bool cmp2(samoch i, samoch j){ return (i.x2<j.x2); } int main(void){ int jjj; scanf("%d", &jjj); while (jjj--) { int n, w, i; bool jestOK = true; scanf("%d %d", &n, &w); samoch * beg = new samoch [n]; for (i=0; i<n; i++) { scanf("%d %d %d %d", &(beg[i].x1), &(beg[i].y1), &(beg[i].x2), &(beg[i].y2)); beg[i].numer = i; } samoch * end = new samoch [n]; for (i=0; i<n; i++) { scanf("%d %d %d %d", &(end[i].x1), &(end[i].y1), &(end[i].x2), &(end[i].y2)); end[i].numer = i; } sort(beg, beg+n, cmp2); sort(end, end+n, cmp1); int *ind = new int [n]; for (i=0; i<n; i++) ind[beg[i].numer]=i; for (i=0; i<n; i++) { int j = ind[end[i].numer]; for (int k=0; k<j; k++) if (end[i].y2-end[i].y1 + beg[k].y2-beg[k].y1>w) jestOK = false; beg[j].y2 = beg[j].y1; } if (jestOK) printf("TAK\n"); else printf("NIE\n"); delete [] ind; delete [] beg; delete [] end; } return 0; } |