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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <cstdio>

struct MIRROR {
    int w_min;
    int w_max;
    int h_min;
    int h_max;
};

int n;
MIRROR * get_input();
bool check_mirrors(MIRROR * mirror, int size);

int main() {
    using namespace std;

    ios_base::sync_with_stdio(0);

    int tests;
    scanf("%d", &tests);

    string * answer = new string [tests];

    for(int i=0; i<tests; i++) {
        // Podaj ilosc luster ...
        scanf("%d", &n);

        if(check_mirrors(get_input(), n)) {
            answer[i] = "TAK";
        }
        else {
            answer[i] = "NIE";
        }
    }

    for(int i=0; i<tests; i++) {
        cout << answer[i] << endl;
    }

    delete [] answer;

    return 0;
}

MIRROR * get_input() {

    MIRROR * mirror = new MIRROR [n];

    for(int i=0; i<n; i++) {
        scanf("%d %d %d %d", &mirror[i].w_min, &mirror[i].w_max, &mirror[i].h_min, &mirror[i].h_max);
    }

    return mirror;
}

bool check_mirrors(MIRROR * mirror, int size) {

    // Sprawdź każde lustro ...
    int curr_w_min = mirror[0].w_min;
    int curr_w_max = mirror[0].w_max;
    int curr_h_min = mirror[0].h_min;
    int curr_h_max = mirror[0].h_max;

    // Zacznij porównywać od następnego lustra
    // Poznajduj najmniejsze wymiary luster

    for(int i=1; i<size; i++) {
        if(curr_w_min >= mirror[i].w_min) {
            curr_w_min = mirror[i].w_min;
        }

        if(curr_w_max <= mirror[i].w_max) {
            curr_w_max = mirror[i].w_max;
        }

        if(curr_h_min >= mirror[i].h_min) {
            curr_h_min = mirror[i].h_min;
        }

        if(curr_h_max <= mirror[i].h_max) {
            curr_h_max = mirror[i].h_max;
        }
    }
    // Sprawdź, czy jakieś lustro ma takie wymiary ...
    for(int i=0; i<size; i++) {
        if(curr_w_min == mirror[i].w_min && curr_w_max == mirror[i].w_max && curr_h_min == mirror[i].h_min && curr_h_max == mirror[i].h_max) {
            return true;
        }
    }

    delete [] mirror;

    return false;
}