import static java.lang.Math.max; import static java.lang.Math.min; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class lus { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){ int t = Integer.parseInt(br.readLine()); while (t-- > 0) System.out.println(auction(br) ? "TAK" : "NIE"); } catch (IOException e) { e.printStackTrace(); } finally { System.exit(0); } } private static boolean auction(BufferedReader br) throws IOException{ int n = Integer.parseInt(br.readLine()); int[][] firms = new int[n][4]; for (int i = 0; i < n; i++){ StringTokenizer st = new StringTokenizer(br.readLine()); firms[i][0] = Integer.parseInt(st.nextToken()); firms[i][1] = Integer.parseInt(st.nextToken()); firms[i][2] = Integer.parseInt(st.nextToken()); firms[i][3] = Integer.parseInt(st.nextToken()); } int[] best = firms[0]; int[] total = Arrays.copyOf(firms[0], 4); for (int i = 1; i < n; i++){ int[] nbest = firms[i]; total[0] = min(total[0], nbest[0]); total[1] = max(total[1], nbest[1]); total[2] = min(total[2], nbest[2]); total[3] = max(total[3], nbest[3]); if (contains(nbest, best)) best = nbest; } return Arrays.equals(total, best); } static boolean contains(int[] f1, int[] f2){ return f1[0] <= f2[0] && f1[1] >= f2[1] && f1[2] <= f2[2] && f1[3] >= f2[3]; } }
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 | import static java.lang.Math.max; import static java.lang.Math.min; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class lus { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){ int t = Integer.parseInt(br.readLine()); while (t-- > 0) System.out.println(auction(br) ? "TAK" : "NIE"); } catch (IOException e) { e.printStackTrace(); } finally { System.exit(0); } } private static boolean auction(BufferedReader br) throws IOException{ int n = Integer.parseInt(br.readLine()); int[][] firms = new int[n][4]; for (int i = 0; i < n; i++){ StringTokenizer st = new StringTokenizer(br.readLine()); firms[i][0] = Integer.parseInt(st.nextToken()); firms[i][1] = Integer.parseInt(st.nextToken()); firms[i][2] = Integer.parseInt(st.nextToken()); firms[i][3] = Integer.parseInt(st.nextToken()); } int[] best = firms[0]; int[] total = Arrays.copyOf(firms[0], 4); for (int i = 1; i < n; i++){ int[] nbest = firms[i]; total[0] = min(total[0], nbest[0]); total[1] = max(total[1], nbest[1]); total[2] = min(total[2], nbest[2]); total[3] = max(total[3], nbest[3]); if (contains(nbest, best)) best = nbest; } return Arrays.equals(total, best); } static boolean contains(int[] f1, int[] f2){ return f1[0] <= f2[0] && f1[1] >= f2[1] && f1[2] <= f2[2] && f1[3] >= f2[3]; } } |