#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<pair<int, int> > M;
vector<pair<int, pair<int, int> > > A;
struct cmp{
bool operator()(const pair<int, int> &a1, const int &a2){
if (a1.first < a2)
return true;
return false;
}
bool operator()(const int &a2, const pair<int, int> &a1){
if (a1.first < a2)
return true;
return false;
}
};
int main()
{
ios_base::sync_with_stdio(0);
int t;
cin>>t;
while(t--)
{
int n, w;
cin>>n>>w;
vector<pair<int, pair<int, int> > > beg;
vector<pair<int, pair<int, int> > > fin;
vector<pair<int, int> > b1;
vector<pair<int, int> > f1;
for(int i=0; i<n; i++)
{
int x1, x2, xpom, ypom, y1, y2;
cin>>xpom>>ypom>>x2>>y2;
x1 = min(xpom, x2);
y1 = min(ypom, y2);
x2 = max(xpom, x2);
y2 = max(ypom, y2);
beg.push_back(make_pair(x1, make_pair(y2-y1, i+1)));
b1.push_back(make_pair(x1, y2-y1));
}
for(int i=0; i<n; i++)
{
int x1, x2, xpom, ypom, y1, y2;
cin>>xpom>>ypom>>x2>>y2;
x1 = min(xpom, x2);
y1 = min(ypom, y2);
x2 = max(xpom, x2);
y2 = max(ypom, y2);
fin.push_back(make_pair(x1, make_pair(y2-y1, i+1)));
f1.push_back(make_pair(x1, y2-y1));
}
sort(beg.begin(), beg.end());
sort(fin.begin(), fin.end());
A.clear();
vector<pair<int, pair<int, int> > > kon;
for(int i=0; i<n; i++)
{
// cout<<beg[i].second.first<<"@#$"<<endl;
if(beg[i].second.first > w/2) A.push_back(beg[i]);
if(fin[i].second.first > w/2) kon.push_back(fin[i]);
}
bool ans = true;
for(int i=0; i<A.size(); i++) if(A[i].second.second != kon[i].second.second) ans = false;
// cout<<A.size()<<"!@#!@#"<<endl;
if(ans == false) cout<<"NIE"<<endl;
else
{
for(int i=0; i<n && ans; i++){
if(b1[i].second <= w/2){
for(int j=0; j<A.size(); j++){
if((A[j].first-b1[i].first > 0 && kon[j].first-f1[i].first < 0) ||
(A[j].first-b1[i].first < 0 && kon[j].first-f1[i].first > 0))
if(A[j].second.first + b1[i].second > w) ans = false;
}
}
}
if(ans) 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; vector<pair<int, int> > M; vector<pair<int, pair<int, int> > > A; struct cmp{ bool operator()(const pair<int, int> &a1, const int &a2){ if (a1.first < a2) return true; return false; } bool operator()(const int &a2, const pair<int, int> &a1){ if (a1.first < a2) return true; return false; } }; int main() { ios_base::sync_with_stdio(0); int t; cin>>t; while(t--) { int n, w; cin>>n>>w; vector<pair<int, pair<int, int> > > beg; vector<pair<int, pair<int, int> > > fin; vector<pair<int, int> > b1; vector<pair<int, int> > f1; for(int i=0; i<n; i++) { int x1, x2, xpom, ypom, y1, y2; cin>>xpom>>ypom>>x2>>y2; x1 = min(xpom, x2); y1 = min(ypom, y2); x2 = max(xpom, x2); y2 = max(ypom, y2); beg.push_back(make_pair(x1, make_pair(y2-y1, i+1))); b1.push_back(make_pair(x1, y2-y1)); } for(int i=0; i<n; i++) { int x1, x2, xpom, ypom, y1, y2; cin>>xpom>>ypom>>x2>>y2; x1 = min(xpom, x2); y1 = min(ypom, y2); x2 = max(xpom, x2); y2 = max(ypom, y2); fin.push_back(make_pair(x1, make_pair(y2-y1, i+1))); f1.push_back(make_pair(x1, y2-y1)); } sort(beg.begin(), beg.end()); sort(fin.begin(), fin.end()); A.clear(); vector<pair<int, pair<int, int> > > kon; for(int i=0; i<n; i++) { // cout<<beg[i].second.first<<"@#$"<<endl; if(beg[i].second.first > w/2) A.push_back(beg[i]); if(fin[i].second.first > w/2) kon.push_back(fin[i]); } bool ans = true; for(int i=0; i<A.size(); i++) if(A[i].second.second != kon[i].second.second) ans = false; // cout<<A.size()<<"!@#!@#"<<endl; if(ans == false) cout<<"NIE"<<endl; else { for(int i=0; i<n && ans; i++){ if(b1[i].second <= w/2){ for(int j=0; j<A.size(); j++){ if((A[j].first-b1[i].first > 0 && kon[j].first-f1[i].first < 0) || (A[j].first-b1[i].first < 0 && kon[j].first-f1[i].first > 0)) if(A[j].second.first + b1[i].second > w) ans = false; } } } if(ans) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; } } return 0; } |
English