import java.util.Scanner;
public class lus{
public static void main(String[] args) {
B1Lustra.main(args);
}
}
class B1Lustra {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int t = sc.nextInt();
for(int i=0; i<t; ++ i){
analizujOpis();
}
}
static class Wymiar{
int min;
int max;
static final int DIFERENT=5;
public Wymiar(int nextInt, int nextInt2) {
min=nextInt;
max = nextInt2;
}
/**
*
* @param w
* @return 1 - gdy this majoryzuje w
* -2 gdy w majoryzuje this
* DIFERENT gdy nie da sie porownac
* 0 gdy rowne
*/
int majoryzuje(Wymiar w){
if(min==w.min && max== w.max)
return 1;
if(min<=w.min && max >=w.max)
return 2;
if(min>=w.min && max <=w.max)
return -2;
return DIFERENT;
}
public static Wymiar read() {
return new Wymiar(sc.nextInt(), sc.nextInt());
}
}
static class Prostokat{
Wymiar wys;
Wymiar szer;
public Prostokat(Wymiar wys, Wymiar szer) {
this.wys = wys;
this.szer = szer;
}
Prostokat wiekszy(Prostokat other){
int wysAns = wys.majoryzuje(other.wys);
int szerAns = szer.majoryzuje(other.szer);
//gdy jeden z nich nie jest majoranta
int ans = wysAns*szerAns;
if(ans%5==0) return null;
if(ans==-4) return null;
if(ans==4) return wysAns>0? this : other;
return wysAns*szerAns>=0?this : other;
}
public static Prostokat read() {
return new Prostokat(Wymiar.read(), Wymiar.read());
}
}
private static void analizujOpis() {
int n = sc.nextInt();
Prostokat answer = Prostokat.read();
--n;
do{
if(answer!=null){
answer = answer.wiekszy(Prostokat.read());}
else{
sc.nextLine();
}
}while(--n>0);
System.out.println(answer==null?"NIE":"TAK");
}
}
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 | import java.util.Scanner; public class lus{ public static void main(String[] args) { B1Lustra.main(args); } } class B1Lustra { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int t = sc.nextInt(); for(int i=0; i<t; ++ i){ analizujOpis(); } } static class Wymiar{ int min; int max; static final int DIFERENT=5; public Wymiar(int nextInt, int nextInt2) { min=nextInt; max = nextInt2; } /** * * @param w * @return 1 - gdy this majoryzuje w * -2 gdy w majoryzuje this * DIFERENT gdy nie da sie porownac * 0 gdy rowne */ int majoryzuje(Wymiar w){ if(min==w.min && max== w.max) return 1; if(min<=w.min && max >=w.max) return 2; if(min>=w.min && max <=w.max) return -2; return DIFERENT; } public static Wymiar read() { return new Wymiar(sc.nextInt(), sc.nextInt()); } } static class Prostokat{ Wymiar wys; Wymiar szer; public Prostokat(Wymiar wys, Wymiar szer) { this.wys = wys; this.szer = szer; } Prostokat wiekszy(Prostokat other){ int wysAns = wys.majoryzuje(other.wys); int szerAns = szer.majoryzuje(other.szer); //gdy jeden z nich nie jest majoranta int ans = wysAns*szerAns; if(ans%5==0) return null; if(ans==-4) return null; if(ans==4) return wysAns>0? this : other; return wysAns*szerAns>=0?this : other; } public static Prostokat read() { return new Prostokat(Wymiar.read(), Wymiar.read()); } } private static void analizujOpis() { int n = sc.nextInt(); Prostokat answer = Prostokat.read(); --n; do{ if(answer!=null){ answer = answer.wiekszy(Prostokat.read());} else{ sc.nextLine(); } }while(--n>0); System.out.println(answer==null?"NIE":"TAK"); } } |
English