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
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class lus {
    public static void main(String[] args) {
        new lus().executeAll(System.in, System.out);
    }

    void executeAll(InputStream in, PrintStream out) {
        Scanner scanner = new Scanner(in);

        int numberOfTests = scanner.nextInt();
        for (int i = 0; i < numberOfTests; i++) {
            int numberOfProviders = scanner.nextInt();
            Rectangle[] offers = new Rectangle[numberOfProviders];
            for (int j = 0; j < numberOfProviders; j++) {
                offers[j] = new Rectangle(
                        scanner.nextInt(), scanner.nextInt(),
                        scanner.nextInt(), scanner.nextInt());
            }

            out.println(doJob(offers) ? "TAK" : "NIE");
        }
    }

    static class Rectangle {
        int minX, maxX;
        int minY, maxY;

        public Rectangle(int minWidth, int maxWidth, int minHeight, int maxHeight) {
            minX = minWidth;
            maxX = maxWidth;

            minY = minHeight;
            maxY = maxHeight;
        }

        void add(Rectangle other)
        {
            minX = Math.min(minX, other.minX);
            maxX = Math.max(maxX, other.maxX);

            minY = Math.min(minY, other.minY);
            maxY = Math.max(maxY, other.maxY);
        }

        @Override
        public boolean equals(Object obj) {
            Rectangle other = (Rectangle) obj;
            return minX == other.minX &&
                    maxX == other.maxX &&
                    minY == other.minY &&
                    maxY == other.maxY;
        }
    }

    boolean doJob(Rectangle[] recs) {
        Rectangle expected = new Rectangle(Integer.MAX_VALUE, 0, Integer.MAX_VALUE, 0);
        Rectangle biggestSoFar = new Rectangle(Integer.MAX_VALUE, 0, Integer.MAX_VALUE, 0);

        for (Rectangle rec : recs){
            expected.add(rec);
            if (expected.equals(rec))
                biggestSoFar = rec;
        }

        return expected.equals(biggestSoFar);
    }
}