#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
int a,b,c,d,w,h,id;
} Tcar;
static int cmpTcar(const void *a, const void *b) {
Tcar *c, *d;
c = (Tcar *)a;
d = (Tcar *)b;
if (c->a == d->a)
return c->c - d->c;
return c->a - d->a;
}
int findTheWay(Tcar *post, int n, int w) {
int i,j;
for (i=0; i<n; ++i) {
for (j=i+1;j<n; ++j) {
if ( post[i].h + post[j].h > w && (
(post[i].a < post[j].b && post[i].d > post[j].c)
|| (post[i].b > post[j].a && post[i].c < post[j].d)
)) {
return 0;
}
}
}
return 1;
}
int solve() {
int n,w;
int a, b, c, d;
int i, ret;
Tcar *pre;
scanf("%d %d\n", &n, &w);
pre = malloc(n*sizeof(*pre));
for (i=0; i<n; ++i) {
scanf("%d %d %d %d\n", &a, &b, &c, &d);
if (a>c) { b = a; a = c; c = b; }
pre[i].a = a;
pre[i].b = c;
pre[i].w = a-c;
if (b>d) { pre[i].h = b-d; } else { pre[i].h = d-b; }
pre[i].id = i;
}
for (i=0; i<n; ++i) {
scanf("%d %d %d %d\n", &a, &b, &c, &d);
if (a>c) { b = a; a = c; c = b; }
pre[i].c = a;
pre[i].d = c;
}
qsort(pre, n, sizeof(*pre), cmpTcar);
ret = findTheWay(pre, n, w);
free(pre);
return ret;
}
int main(void) {
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { int a,b,c,d,w,h,id; } Tcar; static int cmpTcar(const void *a, const void *b) { Tcar *c, *d; c = (Tcar *)a; d = (Tcar *)b; if (c->a == d->a) return c->c - d->c; return c->a - d->a; } int findTheWay(Tcar *post, int n, int w) { int i,j; for (i=0; i<n; ++i) { for (j=i+1;j<n; ++j) { if ( post[i].h + post[j].h > w && ( (post[i].a < post[j].b && post[i].d > post[j].c) || (post[i].b > post[j].a && post[i].c < post[j].d) )) { return 0; } } } return 1; } int solve() { int n,w; int a, b, c, d; int i, ret; Tcar *pre; scanf("%d %d\n", &n, &w); pre = malloc(n*sizeof(*pre)); for (i=0; i<n; ++i) { scanf("%d %d %d %d\n", &a, &b, &c, &d); if (a>c) { b = a; a = c; c = b; } pre[i].a = a; pre[i].b = c; pre[i].w = a-c; if (b>d) { pre[i].h = b-d; } else { pre[i].h = d-b; } pre[i].id = i; } for (i=0; i<n; ++i) { scanf("%d %d %d %d\n", &a, &b, &c, &d); if (a>c) { b = a; a = c; c = b; } pre[i].c = a; pre[i].d = c; } qsort(pre, n, sizeof(*pre), cmpTcar); ret = findTheWay(pre, n, w); free(pre); return ret; } int main(void) { int t; scanf("%d\n", &t); while (t--) { printf(solve() ? "TAK\n" : "NIE\n"); } return 0; } |
English