import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class lus { public static void main(String[] args) throws IOException { Scanner scanner; BufferedReader reader; if (args.length > 0) { scanner = new Scanner(new File(args[0])); reader = new BufferedReader(new FileReader(args[0])); } else { scanner = new Scanner(System.in); reader = new BufferedReader(new InputStreamReader(System.in)); } // int t = scanner.nextInt(); int t = Integer.parseInt(reader.readLine()); for (int i=0; i<t; i++) { // int n = scanner.nextInt(); int n = Integer.parseInt(reader.readLine()); Mirror[] mirrors = new Mirror[n]; for (int j=0; j<n; j++) { // mirrors[j] = Mirror.read(scanner); mirrors[j] = Mirror.read(reader); } System.out.println(new lus().solve(mirrors) ? "TAK" : "NIE"); } } private boolean solve(Mirror[] mirrors) { int w1 = Integer.MAX_VALUE, w2 = Integer.MIN_VALUE; int h1 = Integer.MAX_VALUE, h2 = Integer.MIN_VALUE; for (int i=0; i<mirrors.length; i++) { Mirror mirror = mirrors[i]; w1 = Math.min(w1, mirror.w1); w2 = Math.max(w2, mirror.w2); h1 = Math.min(h1, mirror.h1); h2 = Math.max(h2, mirror.h2); } boolean found = false; for (int i=0; i<mirrors.length && !found; i++) { Mirror mirror = mirrors[i]; found = mirror.w1 == w1 && mirror.w2 == w2 && mirror.h1 == h1 && mirror.h2 == h2; } return found; } static class Mirror { int w1, w2, h1, h2; static Mirror read(Scanner scanner) { Mirror mirror = new Mirror(); mirror.w1 = scanner.nextInt(); mirror.w2 = scanner.nextInt(); mirror.h1 = scanner.nextInt(); mirror.h2 = scanner.nextInt(); return mirror; } static Mirror read(BufferedReader reader) throws IOException { String line = reader.readLine(); StringTokenizer tokenizer = new StringTokenizer(line); Mirror mirror = new Mirror(); mirror.w1 = Integer.parseInt(tokenizer.nextToken()); mirror.w2 = Integer.parseInt(tokenizer.nextToken()); mirror.h1 = Integer.parseInt(tokenizer.nextToken()); mirror.h2 = Integer.parseInt(tokenizer.nextToken()); return mirror; } } }
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 | import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class lus { public static void main(String[] args) throws IOException { Scanner scanner; BufferedReader reader; if (args.length > 0) { scanner = new Scanner(new File(args[0])); reader = new BufferedReader(new FileReader(args[0])); } else { scanner = new Scanner(System.in); reader = new BufferedReader(new InputStreamReader(System.in)); } // int t = scanner.nextInt(); int t = Integer.parseInt(reader.readLine()); for (int i=0; i<t; i++) { // int n = scanner.nextInt(); int n = Integer.parseInt(reader.readLine()); Mirror[] mirrors = new Mirror[n]; for (int j=0; j<n; j++) { // mirrors[j] = Mirror.read(scanner); mirrors[j] = Mirror.read(reader); } System.out.println(new lus().solve(mirrors) ? "TAK" : "NIE"); } } private boolean solve(Mirror[] mirrors) { int w1 = Integer.MAX_VALUE, w2 = Integer.MIN_VALUE; int h1 = Integer.MAX_VALUE, h2 = Integer.MIN_VALUE; for (int i=0; i<mirrors.length; i++) { Mirror mirror = mirrors[i]; w1 = Math.min(w1, mirror.w1); w2 = Math.max(w2, mirror.w2); h1 = Math.min(h1, mirror.h1); h2 = Math.max(h2, mirror.h2); } boolean found = false; for (int i=0; i<mirrors.length && !found; i++) { Mirror mirror = mirrors[i]; found = mirror.w1 == w1 && mirror.w2 == w2 && mirror.h1 == h1 && mirror.h2 == h2; } return found; } static class Mirror { int w1, w2, h1, h2; static Mirror read(Scanner scanner) { Mirror mirror = new Mirror(); mirror.w1 = scanner.nextInt(); mirror.w2 = scanner.nextInt(); mirror.h1 = scanner.nextInt(); mirror.h2 = scanner.nextInt(); return mirror; } static Mirror read(BufferedReader reader) throws IOException { String line = reader.readLine(); StringTokenizer tokenizer = new StringTokenizer(line); Mirror mirror = new Mirror(); mirror.w1 = Integer.parseInt(tokenizer.nextToken()); mirror.w2 = Integer.parseInt(tokenizer.nextToken()); mirror.h1 = Integer.parseInt(tokenizer.nextToken()); mirror.h2 = Integer.parseInt(tokenizer.nextToken()); return mirror; } } } |