#include<cstdio>
using namespace std;
struct range
{
int pocz;
int kon;
};
struct mirror
{
range w;
range h;
};
void input(mirror *t, int n)
{
int i;
for(i=0; i<n; i++)
{
scanf("%d%d%d%d", &t[i].w.pocz, &t[i].w.kon, &t[i].h.pocz, &t[i].h.kon);
}
}
inline bool f(range a, range b) // czy a majoryzuje b (tzn. czy a jest nadrangem b) ; b - range odniesienia
{
return (a.pocz<=b.pocz && a.kon>=b.kon);
}
inline bool g(mirror a, mirror b) // b - mirror odniesienia
{
return (f(a.w,b.w) && f(a.h,b.h));
}
bool fun(mirror *t, int n, int i) // czy i-ty mirror majoryzuje pozostałe
{
int j;
for(j=0; j<i; j++)
{
if(g(t[i],t[j])==false)
{
return false;
}
}
for(j=i+1; j<n; j++)
{
if(g(t[i],t[j])==false)
{
return false;
}
}
return true;
}
bool W(mirror *t, int n) // czy istnieje mirror majoryzujący pozostałe
{
int i;
for(i=0; i<n; i++)
{
if(fun(t,n,i)==true)
{
return true;
}
}
return false;
}
void solve(mirror *t, int n)
{
if(W(t,n)==true)
{
printf("TAK\n");
}
else
{
printf("NIE\n");
}
}
int main()
{
int n,i,t;
scanf("%d", &t);
for(i=0; i<t; i++)
{
scanf("%d", &n);
mirror t[n];
input(t,n);
solve(t,n);
}
return 0;
}
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 | #include<cstdio> using namespace std; struct range { int pocz; int kon; }; struct mirror { range w; range h; }; void input(mirror *t, int n) { int i; for(i=0; i<n; i++) { scanf("%d%d%d%d", &t[i].w.pocz, &t[i].w.kon, &t[i].h.pocz, &t[i].h.kon); } } inline bool f(range a, range b) // czy a majoryzuje b (tzn. czy a jest nadrangem b) ; b - range odniesienia { return (a.pocz<=b.pocz && a.kon>=b.kon); } inline bool g(mirror a, mirror b) // b - mirror odniesienia { return (f(a.w,b.w) && f(a.h,b.h)); } bool fun(mirror *t, int n, int i) // czy i-ty mirror majoryzuje pozostałe { int j; for(j=0; j<i; j++) { if(g(t[i],t[j])==false) { return false; } } for(j=i+1; j<n; j++) { if(g(t[i],t[j])==false) { return false; } } return true; } bool W(mirror *t, int n) // czy istnieje mirror majoryzujący pozostałe { int i; for(i=0; i<n; i++) { if(fun(t,n,i)==true) { return true; } } return false; } void solve(mirror *t, int n) { if(W(t,n)==true) { printf("TAK\n"); } else { printf("NIE\n"); } } int main() { int n,i,t; scanf("%d", &t); for(i=0; i<t; i++) { scanf("%d", &n); mirror t[n]; input(t,n); solve(t,n); } return 0; } |
English