import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; public class par { static boolean can = true; static int w; public static void main(String ... args) throws IOException { int[][] initial = new int[50000][5]; Comparator<int[]> initiatingComparator = new Comparator<int[]>() { @Override public int compare(int[] car1, int[] car2) { if (car1[1] <= car2[0]) { return -1; } else if (car1[0] >= car2[1]) { return 1; } else { return 0; } } }; Comparator<int[]> verifyingComparator = new Comparator<int[]>() { @Override public int compare(int[] car1, int[] car2) { if (car1[3] <= car2[2]) { if (car1[0] >= car2[1]) { if (car1[4] + car2[4] > w) { par.can = false; } } return -1; } else if (car1[2] >= car2[3]) { if (car1[1] <= car2[0]) { if (car1[4] + car2[4] > w) { par.can = false; } } return 1; } else { return 0; } } }; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line = reader.readLine(); int t = Integer.parseInt(line); for(; t > 0; t --) { line = reader.readLine(); String[] splitedLine = line.split(" "); int n = Integer.parseInt(splitedLine[0]); w = Integer.parseInt(splitedLine[1]); for (int j = 0; j < n; j++) { line = reader.readLine(); splitedLine = line.split(" "); int x1 = Integer.parseInt(splitedLine[0]); int y1 = Integer.parseInt(splitedLine[1]); int x2 = Integer.parseInt(splitedLine[2]); int y2 = Integer.parseInt(splitedLine[3]); if (x1 <= x2) { initial[j][0] = x1; initial[j][1] = x2; } else { initial[j][0] = x2; initial[j][1] = x1; } if (y1 <= y2) { initial[j][4] = y2 - y1; } else { initial[j][4] = y1 - y2; } } for (int j = 0; j < n; j++) { line = reader.readLine(); splitedLine = line.split(" "); int x1 = Integer.parseInt(splitedLine[0]); int x2 = Integer.parseInt(splitedLine[2]); if (x1 <= x2) { initial[j][2] = x1; initial[j][3] = x2; } else { initial[j][2] = x2; initial[j][3] = x1; } } Arrays.sort(initial, 0, n, initiatingComparator); par.can = true; Arrays.sort(initial, 0, n, verifyingComparator); if (can) { System.out.println("TAK"); } else { System.out.println("NIE"); } } } }
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 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; public class par { static boolean can = true; static int w; public static void main(String ... args) throws IOException { int[][] initial = new int[50000][5]; Comparator<int[]> initiatingComparator = new Comparator<int[]>() { @Override public int compare(int[] car1, int[] car2) { if (car1[1] <= car2[0]) { return -1; } else if (car1[0] >= car2[1]) { return 1; } else { return 0; } } }; Comparator<int[]> verifyingComparator = new Comparator<int[]>() { @Override public int compare(int[] car1, int[] car2) { if (car1[3] <= car2[2]) { if (car1[0] >= car2[1]) { if (car1[4] + car2[4] > w) { par.can = false; } } return -1; } else if (car1[2] >= car2[3]) { if (car1[1] <= car2[0]) { if (car1[4] + car2[4] > w) { par.can = false; } } return 1; } else { return 0; } } }; BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line = reader.readLine(); int t = Integer.parseInt(line); for(; t > 0; t --) { line = reader.readLine(); String[] splitedLine = line.split(" "); int n = Integer.parseInt(splitedLine[0]); w = Integer.parseInt(splitedLine[1]); for (int j = 0; j < n; j++) { line = reader.readLine(); splitedLine = line.split(" "); int x1 = Integer.parseInt(splitedLine[0]); int y1 = Integer.parseInt(splitedLine[1]); int x2 = Integer.parseInt(splitedLine[2]); int y2 = Integer.parseInt(splitedLine[3]); if (x1 <= x2) { initial[j][0] = x1; initial[j][1] = x2; } else { initial[j][0] = x2; initial[j][1] = x1; } if (y1 <= y2) { initial[j][4] = y2 - y1; } else { initial[j][4] = y1 - y2; } } for (int j = 0; j < n; j++) { line = reader.readLine(); splitedLine = line.split(" "); int x1 = Integer.parseInt(splitedLine[0]); int x2 = Integer.parseInt(splitedLine[2]); if (x1 <= x2) { initial[j][2] = x1; initial[j][3] = x2; } else { initial[j][2] = x2; initial[j][3] = x1; } } Arrays.sort(initial, 0, n, initiatingComparator); par.can = true; Arrays.sort(initial, 0, n, verifyingComparator); if (can) { System.out.println("TAK"); } else { System.out.println("NIE"); } } } } |