import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class lus { public static int[][] bests = new int[4][4]; public static void init(int[][] a) { for (int row = 0; row<4; row++) { a[row][0] = a[row][2] = Integer.MAX_VALUE; a[row][1] = a[row][3] = Integer.MIN_VALUE; } } public static void add(int[] offer) { if (allNotWorse(offer)) { setAll(offer); } else { setAllBetter(offer); } } public static void setAllBetter(int[] offer) { for (int row = 0; row<4; row++) { if (row % 2 == 0) { if (offer[row] < bests[row][row]) { for (int i = 0; i<4; i++) { bests[row][i] = offer[i]; } } } else { if (offer[row] > bests[row][row]) { for (int i = 0; i<4; i++) { bests[row][i] = offer[i]; } } } } } public static boolean allNotWorse(int[] offer) { for (int i = 0; i<4; i++) { if (i % 2 == 0) { if (offer[i] > bests[i][i]) { return false; } } else { if (offer[i] < bests[i][i]) { return false; } } } return true; } public static void print() { for (int row = 0; row<4; row++) { for (int col = 0; col<4; col++) { System.out.print(""+bests[row][col] + " "); } System.out.println(); } } public static void setAll(int[] offer) { for (int row = 0; row<4; row++) { for (int col = 0; col<4; col++) { bests[row][col] = offer[col]; } } } public static boolean isMajorized() { for (int row = 0; row<3; row++) { for (int col = 0; col<4; col++) { if (bests[row][col] != bests[row+1][col]) { return false; } } } return true; } public static class Tokenizer { public static int[] stoints(String line) { String[] ss = line.split(" "); int[] ret = new int[ss.length]; for (int i = 0; i<ss.length; i++) { ret[i] = Integer.valueOf(ss[i]); } return ret; } public static int stoint(String s) { return stoints(s)[0]; } } public static void io() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Tokenizer.stoint(br.readLine()); for (int i = 0; i<n; i++) { int k = Tokenizer.stoint(br.readLine()); init(bests); for (int j = 0; j<k; j++) { int[] offer = Tokenizer.stoints(br.readLine()); add(offer); // print(); } System.out.println(isMajorized() ? "TAK" : "NIE"); } } public static void main(String[] args) throws IOException { io(); } }
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class lus { public static int[][] bests = new int[4][4]; public static void init(int[][] a) { for (int row = 0; row<4; row++) { a[row][0] = a[row][2] = Integer.MAX_VALUE; a[row][1] = a[row][3] = Integer.MIN_VALUE; } } public static void add(int[] offer) { if (allNotWorse(offer)) { setAll(offer); } else { setAllBetter(offer); } } public static void setAllBetter(int[] offer) { for (int row = 0; row<4; row++) { if (row % 2 == 0) { if (offer[row] < bests[row][row]) { for (int i = 0; i<4; i++) { bests[row][i] = offer[i]; } } } else { if (offer[row] > bests[row][row]) { for (int i = 0; i<4; i++) { bests[row][i] = offer[i]; } } } } } public static boolean allNotWorse(int[] offer) { for (int i = 0; i<4; i++) { if (i % 2 == 0) { if (offer[i] > bests[i][i]) { return false; } } else { if (offer[i] < bests[i][i]) { return false; } } } return true; } public static void print() { for (int row = 0; row<4; row++) { for (int col = 0; col<4; col++) { System.out.print(""+bests[row][col] + " "); } System.out.println(); } } public static void setAll(int[] offer) { for (int row = 0; row<4; row++) { for (int col = 0; col<4; col++) { bests[row][col] = offer[col]; } } } public static boolean isMajorized() { for (int row = 0; row<3; row++) { for (int col = 0; col<4; col++) { if (bests[row][col] != bests[row+1][col]) { return false; } } } return true; } public static class Tokenizer { public static int[] stoints(String line) { String[] ss = line.split(" "); int[] ret = new int[ss.length]; for (int i = 0; i<ss.length; i++) { ret[i] = Integer.valueOf(ss[i]); } return ret; } public static int stoint(String s) { return stoints(s)[0]; } } public static void io() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Tokenizer.stoint(br.readLine()); for (int i = 0; i<n; i++) { int k = Tokenizer.stoint(br.readLine()); init(bests); for (int j = 0; j<k; j++) { int[] offer = Tokenizer.stoints(br.readLine()); add(offer); // print(); } System.out.println(isMajorized() ? "TAK" : "NIE"); } } public static void main(String[] args) throws IOException { io(); } } |