import java.io.*; import java.util.Scanner; /** * Created by Kamil on 2014-03-31. */ class lus { //test static boolean outputAutoFlush = false; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter writer = new PrintWriter(System.out, outputAutoFlush); public static void setInput(String inputFilePath) throws FileNotFoundException { br = new BufferedReader(new FileReader(inputFilePath)); sc = new Scanner(new File(inputFilePath)); } public static void setOutput(String outputFilePath) throws FileNotFoundException { writer = new PrintWriter(outputFilePath); } static Scanner sc = new Scanner(System.in); private static final int infty = 2000000000; private static boolean solveInstance() throws IOException { //int mirrorProducers = sc.nextInt(); String line = br.readLine(); int mirrorProducers = Integer.parseInt(line); int lW, hW, lH, hH; int minW, maxW, minH, maxH; boolean candidateExisting = false; minW = minH = infty; maxW = maxH = -1; while (mirrorProducers-- > 0) { line = br.readLine(); String[] parts = line.split(" "); lW = Integer.parseInt(parts[0]); hW = Integer.parseInt(parts[1]); lH = Integer.parseInt(parts[2]); hH = Integer.parseInt(parts[3]); if (lW < minW || lH < minH || hW > maxW || hH > maxH) candidateExisting = false; if (lW <= minW && lH <= minH && hW >= maxW && hH >= maxH) candidateExisting = true; minW = Math.min(minW,lW); minH = Math.min(minH,lH); maxW = Math.max(maxW,hW); maxH = Math.max(maxH,hH); } return candidateExisting; } public static void main(String [] args) throws IOException { //int testCases = sc.nextInt(); String line = br.readLine(); int testCases = Integer.parseInt(line); while (testCases-- > 0){ if (solveInstance() == true) writer.println("TAK"); else writer.println("NIE"); } writer.flush(); } }
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 | import java.io.*; import java.util.Scanner; /** * Created by Kamil on 2014-03-31. */ class lus { //test static boolean outputAutoFlush = false; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter writer = new PrintWriter(System.out, outputAutoFlush); public static void setInput(String inputFilePath) throws FileNotFoundException { br = new BufferedReader(new FileReader(inputFilePath)); sc = new Scanner(new File(inputFilePath)); } public static void setOutput(String outputFilePath) throws FileNotFoundException { writer = new PrintWriter(outputFilePath); } static Scanner sc = new Scanner(System.in); private static final int infty = 2000000000; private static boolean solveInstance() throws IOException { //int mirrorProducers = sc.nextInt(); String line = br.readLine(); int mirrorProducers = Integer.parseInt(line); int lW, hW, lH, hH; int minW, maxW, minH, maxH; boolean candidateExisting = false; minW = minH = infty; maxW = maxH = -1; while (mirrorProducers-- > 0) { line = br.readLine(); String[] parts = line.split(" "); lW = Integer.parseInt(parts[0]); hW = Integer.parseInt(parts[1]); lH = Integer.parseInt(parts[2]); hH = Integer.parseInt(parts[3]); if (lW < minW || lH < minH || hW > maxW || hH > maxH) candidateExisting = false; if (lW <= minW && lH <= minH && hW >= maxW && hH >= maxH) candidateExisting = true; minW = Math.min(minW,lW); minH = Math.min(minH,lH); maxW = Math.max(maxW,hW); maxH = Math.max(maxH,hH); } return candidateExisting; } public static void main(String [] args) throws IOException { //int testCases = sc.nextInt(); String line = br.readLine(); int testCases = Integer.parseInt(line); while (testCases-- > 0){ if (solveInstance() == true) writer.println("TAK"); else writer.println("NIE"); } writer.flush(); } } |