#include <iostream>
using namespace std;
int tab[100000][4];
int main()
{
ios_base::sync_with_stdio(0);
int p;
int f;
cin>>p;
for (int i=0; i<p; i++)
{
cin>>f;
for (int j=0; j<f; j++)
{
cin>>tab[j][0];
cin>>tab[j][1];
cin>>tab[j][2];
cin>>tab[j][3];
}
int w_1 = tab[0][0];
int w_2 = tab[0][1];
int h_1 = tab[0][2];
int h_2 = tab[0][3];
bool spr;
for (int j=1; j<f; j++)
{
if (w_1 <= tab[j][0] && w_2 >= tab[j][1])
spr = true;
else if (w_1 > tab[j][0] && w_2 < tab[j][1])
{
w_1 = tab[j][0];
w_2 = tab[j][1];
spr = true;
}
else
{
if (w_1 >= tab[j][0])
w_1 = tab[j][0];
else
w_2 = tab[j][1];
spr = false;
}
}
if (!spr)
{
cout<<"NIE\n";
continue;
}
else
{
for (int j=1; j<f; j++)
{
if (h_1 <= tab[j][2] && h_2 >= tab[j][3])
spr = true;
else if (h_1 >= tab[j][2] && h_2 <= tab[j][3])
{
h_1 = tab[j][2];
h_2 = tab[j][3];
spr = true;
}
else
{
if (h_1 >= tab[j][2])
h_1 = tab[j][2];
else
h_2 = tab[j][3];
spr = false;
}
}
}
if (!spr)
{
cout<<"NIE\n";
continue;
}
else
{
spr = false;
for (int j=0; j<f; j++)
{
if (tab[j][0] == w_1 && tab[j][1] == w_2 && tab[j][2] == h_1 && tab[j][3] == h_2)
{
spr = true;
break;
}
}
if (spr)
{
cout<<"TAK\n";
}
else
{
cout<<"NIE\n";
}
}
}
}
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 | #include <iostream> using namespace std; int tab[100000][4]; int main() { ios_base::sync_with_stdio(0); int p; int f; cin>>p; for (int i=0; i<p; i++) { cin>>f; for (int j=0; j<f; j++) { cin>>tab[j][0]; cin>>tab[j][1]; cin>>tab[j][2]; cin>>tab[j][3]; } int w_1 = tab[0][0]; int w_2 = tab[0][1]; int h_1 = tab[0][2]; int h_2 = tab[0][3]; bool spr; for (int j=1; j<f; j++) { if (w_1 <= tab[j][0] && w_2 >= tab[j][1]) spr = true; else if (w_1 > tab[j][0] && w_2 < tab[j][1]) { w_1 = tab[j][0]; w_2 = tab[j][1]; spr = true; } else { if (w_1 >= tab[j][0]) w_1 = tab[j][0]; else w_2 = tab[j][1]; spr = false; } } if (!spr) { cout<<"NIE\n"; continue; } else { for (int j=1; j<f; j++) { if (h_1 <= tab[j][2] && h_2 >= tab[j][3]) spr = true; else if (h_1 >= tab[j][2] && h_2 <= tab[j][3]) { h_1 = tab[j][2]; h_2 = tab[j][3]; spr = true; } else { if (h_1 >= tab[j][2]) h_1 = tab[j][2]; else h_2 = tab[j][3]; spr = false; } } } if (!spr) { cout<<"NIE\n"; continue; } else { spr = false; for (int j=0; j<f; j++) { if (tab[j][0] == w_1 && tab[j][1] == w_2 && tab[j][2] == h_1 && tab[j][3] == h_2) { spr = true; break; } } if (spr) { cout<<"TAK\n"; } else { cout<<"NIE\n"; } } } } |
English