import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author user */ public class lus { public static void main(String[] args) throws IOException { String s = "3\n" + "3\n" + "2 3 3 5\n" + "1 4 2 6\n" + "1 3 4 6\n" + "3\n" + "1 5 1 3\n" + "2 4 1 3\n" + "3 4 2 5\n" + "4\n" + "1 2 1 10\n" + "1 2 3 8\n" + "2 2 7 10\n" + "1 2 1 10"; new lus().run(System.in); // new lus().run(s); } public void run(String s) throws IOException { run(new ByteArrayInputStream(s.getBytes())); } public void run(InputStream in) throws IOException { FastScanner sc = new FastScanner(in); int N = sc.nextInt(); for (int p = 0; p < N; p++) { int n = sc.nextInt(); int mw1 = Integer.MAX_VALUE; int mh1 = Integer.MAX_VALUE; int mw2 = 0; int mh2 = 0; boolean result = false; for (int i = 0; i < n; i++) { int w1 = sc.nextInt(); int w2 = sc.nextInt(); int h1 = sc.nextInt(); int h2 = sc.nextInt(); int eq = 0; int better = 0; if (w1 < mw1) { mw1 = w1; better++; } if (h1 < mh1) { mh1 = h1; better++; } if (w2 > mw2) { mw2 = w2; better++; } if (h2 > mh2) { mh2 = h2; better++; } if (w1 == mw1) { eq++; } if (w2 == mw2) { eq++; } if (h1 == mh1) { eq++; } if (h2 == mh2) { eq++; } if (eq == 4) { result = true; } else if (better > 0 && better < 4) { result = false; } } System.out.println(result ? "TAK" : "NIE"); } } public static class FastScanner { private InputStream in; private byte[] buf; private int bufIndex; private int bufMax; public FastScanner(InputStream in) { this.in = in; buf = new byte[16384]; } public FastScanner(String text) { this.in = new ByteArrayInputStream(text.getBytes()); buf = new byte[16384]; } private int nextByte() throws IOException { if (bufIndex < bufMax) { return buf[bufIndex++]; } else if (in.available() > 0) { bufMax = in.read(buf); bufIndex = 0; return buf[bufIndex++]; } else { return Integer.MAX_VALUE; // reached end of stream } } public int nextInt() throws IOException { int b; do { b = nextByte(); if (b == Integer.MAX_VALUE) { throw new IOException("EOF"); } } while (b == ' ' || b == '\n' || b == '\r'); boolean minus = false; if (b == '-') { minus = true; b = nextByte(); if (b == Integer.MAX_VALUE) { throw new IOException("EOF"); } } int result; if (b >= '0' && b <= '9') { result = b - '0'; } else { throw new IllegalStateException("Not a digit: " + (char) b); } while (true) { b = nextByte(); if (b >= '0' && b <= '9') { result *= 10; result += b - '0'; } else { break; } } if (minus) { result = -result; } // System.out.println("readInt: " + result); return result; } } }
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author user */ public class lus { public static void main(String[] args) throws IOException { String s = "3\n" + "3\n" + "2 3 3 5\n" + "1 4 2 6\n" + "1 3 4 6\n" + "3\n" + "1 5 1 3\n" + "2 4 1 3\n" + "3 4 2 5\n" + "4\n" + "1 2 1 10\n" + "1 2 3 8\n" + "2 2 7 10\n" + "1 2 1 10"; new lus().run(System.in); // new lus().run(s); } public void run(String s) throws IOException { run(new ByteArrayInputStream(s.getBytes())); } public void run(InputStream in) throws IOException { FastScanner sc = new FastScanner(in); int N = sc.nextInt(); for (int p = 0; p < N; p++) { int n = sc.nextInt(); int mw1 = Integer.MAX_VALUE; int mh1 = Integer.MAX_VALUE; int mw2 = 0; int mh2 = 0; boolean result = false; for (int i = 0; i < n; i++) { int w1 = sc.nextInt(); int w2 = sc.nextInt(); int h1 = sc.nextInt(); int h2 = sc.nextInt(); int eq = 0; int better = 0; if (w1 < mw1) { mw1 = w1; better++; } if (h1 < mh1) { mh1 = h1; better++; } if (w2 > mw2) { mw2 = w2; better++; } if (h2 > mh2) { mh2 = h2; better++; } if (w1 == mw1) { eq++; } if (w2 == mw2) { eq++; } if (h1 == mh1) { eq++; } if (h2 == mh2) { eq++; } if (eq == 4) { result = true; } else if (better > 0 && better < 4) { result = false; } } System.out.println(result ? "TAK" : "NIE"); } } public static class FastScanner { private InputStream in; private byte[] buf; private int bufIndex; private int bufMax; public FastScanner(InputStream in) { this.in = in; buf = new byte[16384]; } public FastScanner(String text) { this.in = new ByteArrayInputStream(text.getBytes()); buf = new byte[16384]; } private int nextByte() throws IOException { if (bufIndex < bufMax) { return buf[bufIndex++]; } else if (in.available() > 0) { bufMax = in.read(buf); bufIndex = 0; return buf[bufIndex++]; } else { return Integer.MAX_VALUE; // reached end of stream } } public int nextInt() throws IOException { int b; do { b = nextByte(); if (b == Integer.MAX_VALUE) { throw new IOException("EOF"); } } while (b == ' ' || b == '\n' || b == '\r'); boolean minus = false; if (b == '-') { minus = true; b = nextByte(); if (b == Integer.MAX_VALUE) { throw new IOException("EOF"); } } int result; if (b >= '0' && b <= '9') { result = b - '0'; } else { throw new IllegalStateException("Not a digit: " + (char) b); } while (true) { b = nextByte(); if (b >= '0' && b <= '9') { result *= 10; result += b - '0'; } else { break; } } if (minus) { result = -result; } // System.out.println("readInt: " + result); return result; } } } |