import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * @author: Wojciech Krzaczek */ public class lus { public static void main(String[] args) { @SuppressWarnings("resource") Scanner scanner = new Scanner(System.in); final int numberOfTestCases = scanner.nextInt(); List<String> results = new ArrayList<>(); for (int i = 0; i < numberOfTestCases; i++) { int[] parameters = { Integer.MAX_VALUE, 0, Integer.MAX_VALUE, 0 }; int[] parameterOwner = { -1, -1, -1, -1 }; final int numberOfOffers = scanner.nextInt(); for (int j = 0; j < numberOfOffers; j++) { boolean replaced = false; final int WidthMin = scanner.nextInt(); final int WidthMax = scanner.nextInt(); final int HightMin = scanner.nextInt(); final int HightMax = scanner.nextInt(); if(WidthMin == parameters[0] && WidthMax == parameters[1] && HightMin == parameters[2] && HightMax == parameters[3]) { parameters[0] = WidthMin; parameterOwner[0] = j; parameters[1] = WidthMax; parameterOwner[1] = j; parameters[2] = HightMin; parameterOwner[2] = j; parameters[3] = HightMax; parameterOwner[3] = j; continue; } if (WidthMin < parameters[0]) { replaced = true; parameters[0] = WidthMin; parameterOwner[0] = j; } if (WidthMax > parameters[1] && !replaced) { replaced = true; parameters[1] = WidthMax; parameterOwner[1] = j; } if (HightMin < parameters[2] && !replaced) { replaced = true; parameters[2] = HightMin; parameterOwner[2] = j; } if (HightMax > parameters[3] && !replaced) { replaced = true; parameters[3] = HightMax; parameterOwner[3] = j; } if (replaced) { if (WidthMin <= parameters[0]) { parameters[0] = WidthMin; parameterOwner[0] = j; } if (WidthMax >= parameters[1]) { parameters[1] = WidthMax; parameterOwner[1] = j; } if (HightMin <= parameters[2]) { parameters[2] = HightMin; parameterOwner[2] = j; } if (HightMax >= parameters[3]) { parameters[3] = HightMax; parameterOwner[3] = j; } } } results.add(checkIfAllParametersAreSame(parameterOwner)); } printReesults(results); } private static String checkIfAllParametersAreSame(int[] parameterOwner) { final int first = parameterOwner[0]; if (first == parameterOwner[1] && first == parameterOwner[2] && first == parameterOwner[3]) { return "TAK"; } return "NIE"; } private static void printReesults(List<String> results) { for (String testCase : results) { System.out.println(testCase); } } }
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 | import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * @author: Wojciech Krzaczek */ public class lus { public static void main(String[] args) { @SuppressWarnings("resource") Scanner scanner = new Scanner(System.in); final int numberOfTestCases = scanner.nextInt(); List<String> results = new ArrayList<>(); for (int i = 0; i < numberOfTestCases; i++) { int[] parameters = { Integer.MAX_VALUE, 0, Integer.MAX_VALUE, 0 }; int[] parameterOwner = { -1, -1, -1, -1 }; final int numberOfOffers = scanner.nextInt(); for (int j = 0; j < numberOfOffers; j++) { boolean replaced = false; final int WidthMin = scanner.nextInt(); final int WidthMax = scanner.nextInt(); final int HightMin = scanner.nextInt(); final int HightMax = scanner.nextInt(); if(WidthMin == parameters[0] && WidthMax == parameters[1] && HightMin == parameters[2] && HightMax == parameters[3]) { parameters[0] = WidthMin; parameterOwner[0] = j; parameters[1] = WidthMax; parameterOwner[1] = j; parameters[2] = HightMin; parameterOwner[2] = j; parameters[3] = HightMax; parameterOwner[3] = j; continue; } if (WidthMin < parameters[0]) { replaced = true; parameters[0] = WidthMin; parameterOwner[0] = j; } if (WidthMax > parameters[1] && !replaced) { replaced = true; parameters[1] = WidthMax; parameterOwner[1] = j; } if (HightMin < parameters[2] && !replaced) { replaced = true; parameters[2] = HightMin; parameterOwner[2] = j; } if (HightMax > parameters[3] && !replaced) { replaced = true; parameters[3] = HightMax; parameterOwner[3] = j; } if (replaced) { if (WidthMin <= parameters[0]) { parameters[0] = WidthMin; parameterOwner[0] = j; } if (WidthMax >= parameters[1]) { parameters[1] = WidthMax; parameterOwner[1] = j; } if (HightMin <= parameters[2]) { parameters[2] = HightMin; parameterOwner[2] = j; } if (HightMax >= parameters[3]) { parameters[3] = HightMax; parameterOwner[3] = j; } } } results.add(checkIfAllParametersAreSame(parameterOwner)); } printReesults(results); } private static String checkIfAllParametersAreSame(int[] parameterOwner) { final int first = parameterOwner[0]; if (first == parameterOwner[1] && first == parameterOwner[2] && first == parameterOwner[3]) { return "TAK"; } return "NIE"; } private static void printReesults(List<String> results) { for (String testCase : results) { System.out.println(testCase); } } } |