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
77
78
79
#include <stdio.h>

int major(int x, int n, int w1[], int w2[], int h1[], int h2[])
{
    int i;
    int bool = 0;

    for(i = 0 ; i < n ; i++ )
    {
        if(i == x) continue;
        if( (w1[x] <= w1[i]) && (w2[x] >= w2[i]) && (h1[x] <= h1[i]) && (h2[x] >= h2[i]) ) bool = 1;
        else bool = 0;
    }

    return bool;
}

int main()
{
    int jest = 0, j = 0;
    int n, i, t,
        wynik[10];
    int *w1, *w2,
        *h1, *h2;
    const int c = 1000000000;

    do {scanf("%d", &t);}
        while((t < 1) || (t > 10));

    while(j != t)
    {

    do scanf("%d", &n);
        while((n < 2) || (n > 100000));

    w1 = (int*) malloc(n * sizeof *w1);
    w2 = (int*) malloc(n * sizeof *w2);
    h1 = (int*) malloc(n * sizeof *h1);
    h2 = (int*) malloc(n * sizeof *h2);
    jest = 0;

    for(i = 0 ; i < n ; i++)
    {
        do scanf("%d %d %d %d", &w1[i], &w2[i], &h1[i], &h2[i]);
            while( (w1[i] > w2[i]) || (h1[i] > h2[i]) ||
                   (w1[i] < 1) || (w2[i] < 1) ||
                   (w1[i] > c) || (w2[i] > c) ||
                   (h1[i] < 1) || (h2[i] < 1) ||
                   (h1[i] > c) || (h2[i] > c));
    }

    for(i = 0 ; i < n ; i++)
    {
     if(major(i, n, w1, w2, h1, h2))
     {
        jest = 1;
        break;
     }
    }

    if(jest) wynik[j] = 1; else wynik[j] = 0;

    free (w1);
    free (w2);
    free (h1);
    free (h2);

    j++;
    }

    j = 0;

    while(j != t)
    {
        if(wynik[j]) printf("TAK\n"); else printf("NIE\n");
        j++;
    }
    return 0;
}