#include <stdio.h> #include <stdlib.h> int solve() { int n,i,mw1,mw2,mh1,mh2; int *w1, *w2, *h1, *h2; int ret; scanf("%d\n", &n); w1 = malloc(n*sizeof(*w1)); w2 = malloc(n*sizeof(*w2)); h1 = malloc(n*sizeof(*h1)); h2 = malloc(n*sizeof(*h2)); mw1 = mh1 = 2000000000; mw2 = mh2 = 0; for (i=0; i<n; ++i) { scanf("%d %d %d %d\n", w1+i, w2+i, h1+i, h2+i); if (w1[i] < mw1) mw1 = w1[i]; if (w2[i] > mw2) mw2 = w2[i]; if (h1[i] < mh1) mh1 = h1[i]; if (h2[i] > mh2) mh2 = h2[i]; } ret = 0; for (i=0; i<n && !ret; ++i) { if (w1[i] <= mw1 && w2[i] >= mw2 && h1[i] <= mh1 && h2[i] >= mh2) ret = 1; } free(w1); free(w2); free(h1); free(h2); return ret; } int main() { int t; scanf("%d\n", &t); while (t--) { printf(solve() ? "TAK\n" : "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 51 | #include <stdio.h> #include <stdlib.h> int solve() { int n,i,mw1,mw2,mh1,mh2; int *w1, *w2, *h1, *h2; int ret; scanf("%d\n", &n); w1 = malloc(n*sizeof(*w1)); w2 = malloc(n*sizeof(*w2)); h1 = malloc(n*sizeof(*h1)); h2 = malloc(n*sizeof(*h2)); mw1 = mh1 = 2000000000; mw2 = mh2 = 0; for (i=0; i<n; ++i) { scanf("%d %d %d %d\n", w1+i, w2+i, h1+i, h2+i); if (w1[i] < mw1) mw1 = w1[i]; if (w2[i] > mw2) mw2 = w2[i]; if (h1[i] < mh1) mh1 = h1[i]; if (h2[i] > mh2) mh2 = h2[i]; } ret = 0; for (i=0; i<n && !ret; ++i) { if (w1[i] <= mw1 && w2[i] >= mw2 && h1[i] <= mh1 && h2[i] >= mh2) ret = 1; } free(w1); free(w2); free(h1); free(h2); return ret; } int main() { int t; scanf("%d\n", &t); while (t--) { printf(solve() ? "TAK\n" : "NIE\n"); } return 0; } |