import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class lus { public static void main(String [] args ) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; int T; StringBuilder sb = new StringBuilder(); line = br.readLine(); T = Integer.parseInt(line); for(;T>0;T--) { List<Rect> list = new ArrayList<Rect>(); int n; line = br.readLine(); n = Integer.parseInt(line); for(;n>0;n--){ line = br.readLine(); String [] tab = line.split(" "); Rect rect = new Rect(); rect.x = Long.parseLong(tab[0]); rect.width = Long.parseLong(tab[1]) - rect.x; rect.y = Long.parseLong(tab[2]); rect.height = Long.parseLong(tab[3]) - rect.y; list.add(rect); } Rect rect = enclose(list); boolean exists= false; for(Rect rect1: list){ if(rect1.x == rect.x && rect1.y == rect.y && rect1.width == rect.width && rect1.height == rect.height){ exists = true; break; } } if(exists) { sb.append("TAK"); } else { sb.append("NIE"); } if(T>1) sb.append('\n'); } System.out.print(sb); } static Rect enclose(List<Rect> list) { long topLeftX = Integer.MAX_VALUE; long topLeftY = Integer.MAX_VALUE; long bottomRightX = Integer.MIN_VALUE; long bottomRightY = Integer.MIN_VALUE; for (Rect r : list) { if (r.x < topLeftX) topLeftX = r.x; if (r.y < topLeftY) topLeftY = r.y; if ((r.x + r.width) > bottomRightX) bottomRightX = (r.x + r.width); if ((r.y + r.height) > bottomRightY) bottomRightY = (r.y + r.height); } Rect res = new Rect(); res.x = topLeftX; res.y = topLeftY; res.width= bottomRightX - topLeftX;res.height = bottomRightY - topLeftY; return res; } static class Rect { long x,y,width,height; } }
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 | import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class lus { public static void main(String [] args ) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; int T; StringBuilder sb = new StringBuilder(); line = br.readLine(); T = Integer.parseInt(line); for(;T>0;T--) { List<Rect> list = new ArrayList<Rect>(); int n; line = br.readLine(); n = Integer.parseInt(line); for(;n>0;n--){ line = br.readLine(); String [] tab = line.split(" "); Rect rect = new Rect(); rect.x = Long.parseLong(tab[0]); rect.width = Long.parseLong(tab[1]) - rect.x; rect.y = Long.parseLong(tab[2]); rect.height = Long.parseLong(tab[3]) - rect.y; list.add(rect); } Rect rect = enclose(list); boolean exists= false; for(Rect rect1: list){ if(rect1.x == rect.x && rect1.y == rect.y && rect1.width == rect.width && rect1.height == rect.height){ exists = true; break; } } if(exists) { sb.append("TAK"); } else { sb.append("NIE"); } if(T>1) sb.append('\n'); } System.out.print(sb); } static Rect enclose(List<Rect> list) { long topLeftX = Integer.MAX_VALUE; long topLeftY = Integer.MAX_VALUE; long bottomRightX = Integer.MIN_VALUE; long bottomRightY = Integer.MIN_VALUE; for (Rect r : list) { if (r.x < topLeftX) topLeftX = r.x; if (r.y < topLeftY) topLeftY = r.y; if ((r.x + r.width) > bottomRightX) bottomRightX = (r.x + r.width); if ((r.y + r.height) > bottomRightY) bottomRightY = (r.y + r.height); } Rect res = new Rect(); res.x = topLeftX; res.y = topLeftY; res.width= bottomRightX - topLeftX;res.height = bottomRightY - topLeftY; return res; } static class Rect { long x,y,width,height; } } |