#include <stdio.h> #include <stdlib.h> #define MAX 50000 int main() { int xi[MAX]; int xip[MAX]; int hi[MAX]; int t, ti, i, wp, j, w, n, x1, x2, y1, y2; char htwp, ocf, nieflag, bylaodp; scanf("%d", &t); for (ti = 0; ti < t; ++ti) { bylaodp = 0; scanf("%d %d", &n, &w); wp = w/2; htwp = 0; for(i = 0; i < n; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xi[i] = x1 < x2 ? x1 : x2 ; hi[i] = y1 < y2 ? y2 - y1 : y1 - y2; if (hi[i] > wp) { htwp = 1; } } ocf = 0; for(i = 0; i < n; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xip[i] = x1 < x2 ? x1 : x2 ; if (xip[i] != xi[i]) { ocf = 1; } } if (htwp == 0) { printf("TAK\n"); bylaodp = 1; continue; } if (ocf == 0) { printf("TAK\n"); bylaodp = 1; continue; } nieflag = 0; for (i = 0; i < n - 1 && nieflag == 0; ++i) { for (j = i + 1; j < n && nieflag == 0; ++j) { if (hi[i] + hi[j] > w && ((xi[i] < xi[j] && xip[i] > xip[j]) || (xi[i] > xi[j] && xip[i] < xip[j]))) { printf("NIE\n"); bylaodp = 1; nieflag = 1; } } } if (bylaodp == 0) { printf("TAK\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 57 58 59 | #include <stdio.h> #include <stdlib.h> #define MAX 50000 int main() { int xi[MAX]; int xip[MAX]; int hi[MAX]; int t, ti, i, wp, j, w, n, x1, x2, y1, y2; char htwp, ocf, nieflag, bylaodp; scanf("%d", &t); for (ti = 0; ti < t; ++ti) { bylaodp = 0; scanf("%d %d", &n, &w); wp = w/2; htwp = 0; for(i = 0; i < n; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xi[i] = x1 < x2 ? x1 : x2 ; hi[i] = y1 < y2 ? y2 - y1 : y1 - y2; if (hi[i] > wp) { htwp = 1; } } ocf = 0; for(i = 0; i < n; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xip[i] = x1 < x2 ? x1 : x2 ; if (xip[i] != xi[i]) { ocf = 1; } } if (htwp == 0) { printf("TAK\n"); bylaodp = 1; continue; } if (ocf == 0) { printf("TAK\n"); bylaodp = 1; continue; } nieflag = 0; for (i = 0; i < n - 1 && nieflag == 0; ++i) { for (j = i + 1; j < n && nieflag == 0; ++j) { if (hi[i] + hi[j] > w && ((xi[i] < xi[j] && xip[i] > xip[j]) || (xi[i] > xi[j] && xip[i] < xip[j]))) { printf("NIE\n"); bylaodp = 1; nieflag = 1; } } } if (bylaodp == 0) { printf("TAK\n"); } } return 0; } |