import java.util.Scanner; public class lus { /** * @param args */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int noTestCases = in.nextInt(); for (int testCase=0; testCase<noTestCases; testCase++) { long[] res = new long[] { -1, -1, -1, -1}; int noOfCompanies = in.nextInt(); long[][] tab = new long[noOfCompanies][]; for (int compNum=0; compNum < noOfCompanies; compNum++) { tab[compNum] = new long[4]; tab[compNum][0] = in.nextLong(); tab[compNum][1] = in.nextLong(); tab[compNum][2] = in.nextLong(); tab[compNum][3] = in.nextLong(); res[0] = minMax(res[0], tab[compNum][0], true); res[1] = minMax(res[1], tab[compNum][1], false); res[2] = minMax(res[2], tab[compNum][2], true); res[3] = minMax(res[3], tab[compNum][3], false); } boolean end = false; for (int compNum=0; compNum < noOfCompanies; compNum++) { if (tab[compNum][0] == res[0] && tab[compNum][1] == res[1] && tab[compNum][2] == res[2] && tab[compNum][3] == res[3]) { end = true; break; } } if (end) { System.out.println("TAK"); } else { System.out.println("NIE"); } } in.close(); } private static long minMax(long current, long newNum, boolean min) { if (current == -1) { return newNum; } else { if (min) { return Math.min(current, newNum); } else { return Math.max(current, newNum); } } } }
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 | import java.util.Scanner; public class lus { /** * @param args */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int noTestCases = in.nextInt(); for (int testCase=0; testCase<noTestCases; testCase++) { long[] res = new long[] { -1, -1, -1, -1}; int noOfCompanies = in.nextInt(); long[][] tab = new long[noOfCompanies][]; for (int compNum=0; compNum < noOfCompanies; compNum++) { tab[compNum] = new long[4]; tab[compNum][0] = in.nextLong(); tab[compNum][1] = in.nextLong(); tab[compNum][2] = in.nextLong(); tab[compNum][3] = in.nextLong(); res[0] = minMax(res[0], tab[compNum][0], true); res[1] = minMax(res[1], tab[compNum][1], false); res[2] = minMax(res[2], tab[compNum][2], true); res[3] = minMax(res[3], tab[compNum][3], false); } boolean end = false; for (int compNum=0; compNum < noOfCompanies; compNum++) { if (tab[compNum][0] == res[0] && tab[compNum][1] == res[1] && tab[compNum][2] == res[2] && tab[compNum][3] == res[3]) { end = true; break; } } if (end) { System.out.println("TAK"); } else { System.out.println("NIE"); } } in.close(); } private static long minMax(long current, long newNum, boolean min) { if (current == -1) { return newNum; } else { if (min) { return Math.min(current, newNum); } else { return Math.max(current, newNum); } } } } |