import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class lus {
public static void main(String[] args) throws Exception {
new lus().solve(new BufferedReader(new InputStreamReader(System.in)),
new BufferedWriter(new OutputStreamWriter(System.out)));
}
public void solve(BufferedReader reader, BufferedWriter writer) throws Exception {
StringTokenizer st = new StringTokenizer(reader.readLine());
int t = Integer.parseInt(st.nextToken());
for (int i = 0; i < t; i++) {
st = new StringTokenizer(reader.readLine());
int n = Integer.parseInt(st.nextToken());
Dimensions max = null;
Dimensions winner = null;
for (int j = 0; j < n; j++) {
st = new StringTokenizer(reader.readLine());
Dimensions dim = new Dimensions(
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()));
if (max == null) {
max = dim;
winner = dim;
} else if (winner != null) {
if (winner.isSubset(dim)) {
winner = dim;
max = dim;
} else if (!dim.isSubset(winner)) {
winner = null;
max.maximize(dim);
}
} else {
if (max.isSubset(dim)) {
winner = dim;
max = dim;
} else {
max.maximize(dim);
}
}
}
writer.append(winner == null ? "NIE" : "TAK");
writer.newLine();
}
writer.flush();
}
private static class Dimensions {
int w_min, w_max, h_min, h_max;
public Dimensions(int w_min, int w_max, int h_min, int h_max) {
this.w_min = w_min;
this.w_max = w_max;
this.h_min = h_min;
this.h_max = h_max;
}
boolean isSubset(Dimensions that) {
return this.w_min >= that.w_min && this.w_max <= that.w_max && this.h_min >= that.h_min && this.h_max <= that.h_max;
}
void maximize(Dimensions that) {
this.h_max = Math.max(this.h_max, that.h_max);
this.w_max = Math.max(this.w_max, that.w_max);
this.h_min = Math.min(this.h_min, that.h_min);
this.w_min = Math.min(this.w_min, that.w_min);
}
}
}
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 | import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class lus { public static void main(String[] args) throws Exception { new lus().solve(new BufferedReader(new InputStreamReader(System.in)), new BufferedWriter(new OutputStreamWriter(System.out))); } public void solve(BufferedReader reader, BufferedWriter writer) throws Exception { StringTokenizer st = new StringTokenizer(reader.readLine()); int t = Integer.parseInt(st.nextToken()); for (int i = 0; i < t; i++) { st = new StringTokenizer(reader.readLine()); int n = Integer.parseInt(st.nextToken()); Dimensions max = null; Dimensions winner = null; for (int j = 0; j < n; j++) { st = new StringTokenizer(reader.readLine()); Dimensions dim = new Dimensions( Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())); if (max == null) { max = dim; winner = dim; } else if (winner != null) { if (winner.isSubset(dim)) { winner = dim; max = dim; } else if (!dim.isSubset(winner)) { winner = null; max.maximize(dim); } } else { if (max.isSubset(dim)) { winner = dim; max = dim; } else { max.maximize(dim); } } } writer.append(winner == null ? "NIE" : "TAK"); writer.newLine(); } writer.flush(); } private static class Dimensions { int w_min, w_max, h_min, h_max; public Dimensions(int w_min, int w_max, int h_min, int h_max) { this.w_min = w_min; this.w_max = w_max; this.h_min = h_min; this.h_max = h_max; } boolean isSubset(Dimensions that) { return this.w_min >= that.w_min && this.w_max <= that.w_max && this.h_min >= that.h_min && this.h_max <= that.h_max; } void maximize(Dimensions that) { this.h_max = Math.max(this.h_max, that.h_max); this.w_max = Math.max(this.w_max, that.w_max); this.h_min = Math.min(this.h_min, that.h_min); this.w_min = Math.min(this.w_min, that.w_min); } } } |
English