import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class lus {
public InputStream getInputStream() throws FileNotFoundException {
return System.in;
// return new FileInputStream(new File("lus.txt"));
}
public PrintStream getOutputStream() {
return System.out;
}
private int minw = Integer.MAX_VALUE;
private int maxw = Integer.MIN_VALUE;
private int minh = Integer.MAX_VALUE;
private int maxh = Integer.MIN_VALUE;
private LinkedList<Firm> firmList;
public void init() {
minw = Integer.MAX_VALUE;
maxw = Integer.MIN_VALUE;
minh = Integer.MAX_VALUE;
maxh = Integer.MIN_VALUE;
firmList = new LinkedList<Firm>();
}
class Firm {
int w1;
int w2;
int h1;
int h2;
public Firm(int w1, int w2, int h1, int h2) {
this.w1 = w1;
this.w2 = w2;
this.h1 = h1;
this.h2 = h2;
}
}
public void process() {
BufferedReader reader = null;
try {
InputStream in = getInputStream();
PrintStream out = getOutputStream();
reader = new BufferedReader(new InputStreamReader(in));
Integer tests = Integer.valueOf(reader.readLine());
for (int i = 0; i < tests; i++) {
init();
long firms = Long.valueOf(reader.readLine());
for (int j = 0; j < firms; j++) {
readFirm(reader, out);
}
if (firmList.size() <= 1) {
out.println("TAK");
} else {
boolean check = checkFirms();
if (check) {
out.println("TAK");
} else {
out.println("NIE");
}
}
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
private void readFirm(BufferedReader reader, PrintStream out)
throws IOException {
String line = reader.readLine();
StringTokenizer tokenizer = new StringTokenizer(line);
int w1 = Integer.valueOf(tokenizer.nextToken());
int w2 = Integer.valueOf(tokenizer.nextToken());
int h1 = Integer.valueOf(tokenizer.nextToken());
int h2 = Integer.valueOf(tokenizer.nextToken());
minw = Math.min(minw, w1);
maxw = Math.max(maxw, w2);
minh = Math.min(minh, h1);
maxh = Math.max(maxh, h2);
firmList.add(new Firm(w1, w2, h1, h2));
}
private boolean checkFirms() {
for (Iterator<Firm> iterator = firmList.iterator(); iterator.hasNext();) {
Firm firm = iterator.next();
if (firm.w1 == minw && firm.w2 == maxw && firm.h1 == minh
&& firm.h2 == maxh) {
return true;
}
}
return false;
}
public static void main(String[] args) {
lus lus = new lus();
lus.process();
}
}
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 | import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Iterator; import java.util.LinkedList; import java.util.StringTokenizer; public class lus { public InputStream getInputStream() throws FileNotFoundException { return System.in; // return new FileInputStream(new File("lus.txt")); } public PrintStream getOutputStream() { return System.out; } private int minw = Integer.MAX_VALUE; private int maxw = Integer.MIN_VALUE; private int minh = Integer.MAX_VALUE; private int maxh = Integer.MIN_VALUE; private LinkedList<Firm> firmList; public void init() { minw = Integer.MAX_VALUE; maxw = Integer.MIN_VALUE; minh = Integer.MAX_VALUE; maxh = Integer.MIN_VALUE; firmList = new LinkedList<Firm>(); } class Firm { int w1; int w2; int h1; int h2; public Firm(int w1, int w2, int h1, int h2) { this.w1 = w1; this.w2 = w2; this.h1 = h1; this.h2 = h2; } } public void process() { BufferedReader reader = null; try { InputStream in = getInputStream(); PrintStream out = getOutputStream(); reader = new BufferedReader(new InputStreamReader(in)); Integer tests = Integer.valueOf(reader.readLine()); for (int i = 0; i < tests; i++) { init(); long firms = Long.valueOf(reader.readLine()); for (int j = 0; j < firms; j++) { readFirm(reader, out); } if (firmList.size() <= 1) { out.println("TAK"); } else { boolean check = checkFirms(); if (check) { out.println("TAK"); } else { out.println("NIE"); } } } } catch (Throwable t) { t.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (Throwable t) { t.printStackTrace(); } } } } private void readFirm(BufferedReader reader, PrintStream out) throws IOException { String line = reader.readLine(); StringTokenizer tokenizer = new StringTokenizer(line); int w1 = Integer.valueOf(tokenizer.nextToken()); int w2 = Integer.valueOf(tokenizer.nextToken()); int h1 = Integer.valueOf(tokenizer.nextToken()); int h2 = Integer.valueOf(tokenizer.nextToken()); minw = Math.min(minw, w1); maxw = Math.max(maxw, w2); minh = Math.min(minh, h1); maxh = Math.max(maxh, h2); firmList.add(new Firm(w1, w2, h1, h2)); } private boolean checkFirms() { for (Iterator<Firm> iterator = firmList.iterator(); iterator.hasNext();) { Firm firm = iterator.next(); if (firm.w1 == minw && firm.w2 == maxw && firm.h1 == minh && firm.h2 == maxh) { return true; } } return false; } public static void main(String[] args) { lus lus = new lus(); lus.process(); } } |
English