import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class lus { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for (int i = 0; i < t ; i++){ int n = s.nextInt(); int[][] data = new int[n][4]; for (int j = 0; j < n; j++){ for (int k = 0; k < 4; k++){ data[j][k] = s.nextInt(); } for (int p = 0; p<2; p++){ if (data[j][p] > data[j][p+2]){ int tmp = data[j][p]; data[j][p] = data[j][p+2]; data[j][p+2] = tmp; } } } String res = "NIE"; if (hasWinner(data)){ res = "TAK"; } System.out.println(res); } s.close(); } public static boolean hasWinner(int[][] users){ int[] pmin = users[0]; int[] pmax = users[0]; for (int i = 1; i < users.length; i++){ if (users[i][0] < pmin[0]){ pmin = users[i]; } else if (users[i][0] == pmin[0]){ if (users[i][2] < pmin[2]){ pmin = users[i]; // System.out.println("pmin:"+Arrays.deepToString(new int[][]{pmin})); } else if (users[i][2] == pmin[2]){ if (users[i][1] > pmin[1]){ pmin = users[i]; } else if (users[i][1] == pmin[1]){ if (users[i][3] >= pmin[3]){ pmin = users[i]; // System.out.println("pmax:"+Arrays.deepToString(new int[][]{pmax})); } } } } if (users[i][1] > pmax[1]){ pmax = users[i]; } else if (users[i][1] == pmax[1]){ if (users[i][3] > pmax[3]){ pmax = users[i]; // System.out.println("pmax:"+Arrays.deepToString(new int[][]{pmax})); } else if (users[i][3] == pmax[3]){ if (users[i][0] < pmax[0]){ pmax = users[i]; } else if (users[i][1] == pmax[1]){ if (users[i][2] <= pmax[2]){ pmax = users[i]; // System.out.println("pmax:"+Arrays.deepToString(new int[][]{pmax})); } } } } } if (pmin != pmax){ // System.out.println(Arrays.deepToString(new int[][]{pmin,pmax})); return false; } // System.out.println(Arrays.deepToString(new int[][]{pmin,pmax})); for (int i = 1; i < users.length; i++){ if (users[i][0] < pmin[0] || users[i][2] < pmin[2]){ return false; } if (users[i][1] > pmax[1] || users[i][3] > pmax[3]){ return false; } } return true; } }
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 | import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class lus { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for (int i = 0; i < t ; i++){ int n = s.nextInt(); int[][] data = new int[n][4]; for (int j = 0; j < n; j++){ for (int k = 0; k < 4; k++){ data[j][k] = s.nextInt(); } for (int p = 0; p<2; p++){ if (data[j][p] > data[j][p+2]){ int tmp = data[j][p]; data[j][p] = data[j][p+2]; data[j][p+2] = tmp; } } } String res = "NIE"; if (hasWinner(data)){ res = "TAK"; } System.out.println(res); } s.close(); } public static boolean hasWinner(int[][] users){ int[] pmin = users[0]; int[] pmax = users[0]; for (int i = 1; i < users.length; i++){ if (users[i][0] < pmin[0]){ pmin = users[i]; } else if (users[i][0] == pmin[0]){ if (users[i][2] < pmin[2]){ pmin = users[i]; // System.out.println("pmin:"+Arrays.deepToString(new int[][]{pmin})); } else if (users[i][2] == pmin[2]){ if (users[i][1] > pmin[1]){ pmin = users[i]; } else if (users[i][1] == pmin[1]){ if (users[i][3] >= pmin[3]){ pmin = users[i]; // System.out.println("pmax:"+Arrays.deepToString(new int[][]{pmax})); } } } } if (users[i][1] > pmax[1]){ pmax = users[i]; } else if (users[i][1] == pmax[1]){ if (users[i][3] > pmax[3]){ pmax = users[i]; // System.out.println("pmax:"+Arrays.deepToString(new int[][]{pmax})); } else if (users[i][3] == pmax[3]){ if (users[i][0] < pmax[0]){ pmax = users[i]; } else if (users[i][1] == pmax[1]){ if (users[i][2] <= pmax[2]){ pmax = users[i]; // System.out.println("pmax:"+Arrays.deepToString(new int[][]{pmax})); } } } } } if (pmin != pmax){ // System.out.println(Arrays.deepToString(new int[][]{pmin,pmax})); return false; } // System.out.println(Arrays.deepToString(new int[][]{pmin,pmax})); for (int i = 1; i < users.length; i++){ if (users[i][0] < pmin[0] || users[i][2] < pmin[2]){ return false; } if (users[i][1] > pmax[1] || users[i][3] > pmax[3]){ return false; } } return true; } } |