#include <iostream>
#include <vector>
#define inf 2000000000
using namespace std;
int n,h,t;
struct autko{
int x1,y1,x2,y2,id;
};
//bool ros (autko i,autko j) { return (i.x1<j.x1); }
vector<autko>tab;
vector<autko>cel;
int xx1,xy1,xx2,xy2;
autko f(){
cin>>xx1>>xy1>>xx2>>xy2;
autko d;
if(xx1<xx2 && xy1<xy2){
d.x1=xx1;
d.y1=xy1;
d.x2=xx2;
d.y2=xy2;
}
else
if(xx1>xx2 && xy1>xy2){
d.x1=xx2;
d.y1=xy2;
d.x2=xx1;
d.y2=xy1;
}
else
if(xx1<xx2 && xy1>xy2){
int height = xy1 - xy2;
d.x1=xx1;
d.y1=xy1-height;
d.x2=xx2;
d.y2=xy2+height;
}
else
if(xx1>xx2 && xy1<xy2){
int height = xy2 - xy1;
d.x1=xx2;
d.y1=xy2-height;
d.x2=xx1;
d.y2=xy1+height;
}
return d;
}
int main() {
ios_base::sync_with_stdio(0);
cin>>t;
for(int q=0; q<t; q++){
tab.clear();
cel.clear();
cin>>n>>h;
for(int i =0; i<n; i++){
tab.push_back(f());
}
for(int i =0; i<n; i++){
cel.push_back(f());
}
// sort (tab.begin(), tab.end(), ros);
// sort (cel.begin(), cel.end(), ros);
bool ok = true;
for (int i =0; i< n; i++){
// cout<<"PRZENOSINY "<<i+1<<endl;
int wyso = tab[i].y2-tab[i].y1;
if(tab[i].x1<cel[i].x1)
for(int j = 0; j<n; j++){
if(i==j)j++;
// cout<<"SPRAWDZAMY Z "<<j+1<<endl;
if(tab[j].x1>=tab[i].x1 && tab[j].x1<=cel[i].x1){
if(h< wyso + tab[j].y2 - tab[j].y1) {
ok =false;
// cout<<"tu sie psuje"<<endl;
}
}
}
else
for(int j = 0; j<n; j++){
if(i==j)j++;
// cout<<"sPRAWDZAMY Z "<<j+1<<endl;
if(tab[j].x1<=tab[i].x1 && tab[j].x1>=cel[i].x1){
if(h< wyso + tab[j].y2 - tab[j].y1){
ok =false;
// cout<<"tu sie psuje"<<endl;
}
}
}
}
if(ok)cout<<"TAK"<<endl;
else cout<<"NIE"<<endl;
}
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #include <iostream> #include <vector> #define inf 2000000000 using namespace std; int n,h,t; struct autko{ int x1,y1,x2,y2,id; }; //bool ros (autko i,autko j) { return (i.x1<j.x1); } vector<autko>tab; vector<autko>cel; int xx1,xy1,xx2,xy2; autko f(){ cin>>xx1>>xy1>>xx2>>xy2; autko d; if(xx1<xx2 && xy1<xy2){ d.x1=xx1; d.y1=xy1; d.x2=xx2; d.y2=xy2; } else if(xx1>xx2 && xy1>xy2){ d.x1=xx2; d.y1=xy2; d.x2=xx1; d.y2=xy1; } else if(xx1<xx2 && xy1>xy2){ int height = xy1 - xy2; d.x1=xx1; d.y1=xy1-height; d.x2=xx2; d.y2=xy2+height; } else if(xx1>xx2 && xy1<xy2){ int height = xy2 - xy1; d.x1=xx2; d.y1=xy2-height; d.x2=xx1; d.y2=xy1+height; } return d; } int main() { ios_base::sync_with_stdio(0); cin>>t; for(int q=0; q<t; q++){ tab.clear(); cel.clear(); cin>>n>>h; for(int i =0; i<n; i++){ tab.push_back(f()); } for(int i =0; i<n; i++){ cel.push_back(f()); } // sort (tab.begin(), tab.end(), ros); // sort (cel.begin(), cel.end(), ros); bool ok = true; for (int i =0; i< n; i++){ // cout<<"PRZENOSINY "<<i+1<<endl; int wyso = tab[i].y2-tab[i].y1; if(tab[i].x1<cel[i].x1) for(int j = 0; j<n; j++){ if(i==j)j++; // cout<<"SPRAWDZAMY Z "<<j+1<<endl; if(tab[j].x1>=tab[i].x1 && tab[j].x1<=cel[i].x1){ if(h< wyso + tab[j].y2 - tab[j].y1) { ok =false; // cout<<"tu sie psuje"<<endl; } } } else for(int j = 0; j<n; j++){ if(i==j)j++; // cout<<"sPRAWDZAMY Z "<<j+1<<endl; if(tab[j].x1<=tab[i].x1 && tab[j].x1>=cel[i].x1){ if(h< wyso + tab[j].y2 - tab[j].y1){ ok =false; // cout<<"tu sie psuje"<<endl; } } } } if(ok)cout<<"TAK"<<endl; else cout<<"NIE"<<endl; } return 0; } |
English