#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <map> #include <cmath> using namespace std; typedef vector<int> VI; typedef long long LL; typedef pair<int, int> pii; #define REP(x, n) for(int x = 0; x < (n); ++x) #define MP(x,y) make_pair(x,y) #define ALL(x) (x).begin(), (x).end() #define FT first #define ST second #define FOREACH(i, c) for(typeof((c.begin())) i = (c).begin() ; i != (c).end(); ++i) #define PB(x) push_back((x)) #define SZ(x) (int)x.size() #define LN(x) (int)(x).length() struct Rec { int x0,x1,y0,y1,i, xa0, xa1, ya0, ya1; Rec(int x0_, int x1_, int y0_, int y1_, int i_) : x0(x0_), x1(x1_), y0(y0_), y1(y1_), i(i_) {} }; bool cmp(const Rec& r0, const Rec& r1) { return (r0.xa0 != r1.xa0) ? r0.xa0 < r1.xa0 : r0.ya0 < r1.ya0; } bool algo() { int n,m; cin >> n >> m; vector<Rec> rec; rec.reserve(n); REP(i, n) { int x0,x1,y0,y1; cin >> x0 >> y0 >> x1 >> y1; rec.PB(Rec(x0,x1,y0,y1,i)); } REP(i, n) cin >> rec[i].xa0 >> rec[i].ya0 >> rec[i].xa1 >> rec[i].ya1; sort(ALL(rec), cmp); REP(i, n) REP(j, i) { if(rec[i].x0 < rec[j].x0) { if(m < abs(rec[i].y0 - rec[i].y1) + abs(rec[j].y0 - rec[j].y1)) { return false; } } } return true; } int main() { ios_base::sync_with_stdio(0); int tc; cin >> tc; while(tc--) cout << (algo() ? "TAK\n" : "NIE\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 | #include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <map> #include <cmath> using namespace std; typedef vector<int> VI; typedef long long LL; typedef pair<int, int> pii; #define REP(x, n) for(int x = 0; x < (n); ++x) #define MP(x,y) make_pair(x,y) #define ALL(x) (x).begin(), (x).end() #define FT first #define ST second #define FOREACH(i, c) for(typeof((c.begin())) i = (c).begin() ; i != (c).end(); ++i) #define PB(x) push_back((x)) #define SZ(x) (int)x.size() #define LN(x) (int)(x).length() struct Rec { int x0,x1,y0,y1,i, xa0, xa1, ya0, ya1; Rec(int x0_, int x1_, int y0_, int y1_, int i_) : x0(x0_), x1(x1_), y0(y0_), y1(y1_), i(i_) {} }; bool cmp(const Rec& r0, const Rec& r1) { return (r0.xa0 != r1.xa0) ? r0.xa0 < r1.xa0 : r0.ya0 < r1.ya0; } bool algo() { int n,m; cin >> n >> m; vector<Rec> rec; rec.reserve(n); REP(i, n) { int x0,x1,y0,y1; cin >> x0 >> y0 >> x1 >> y1; rec.PB(Rec(x0,x1,y0,y1,i)); } REP(i, n) cin >> rec[i].xa0 >> rec[i].ya0 >> rec[i].xa1 >> rec[i].ya1; sort(ALL(rec), cmp); REP(i, n) REP(j, i) { if(rec[i].x0 < rec[j].x0) { if(m < abs(rec[i].y0 - rec[i].y1) + abs(rec[j].y0 - rec[j].y1)) { return false; } } } return true; } int main() { ios_base::sync_with_stdio(0); int tc; cin >> tc; while(tc--) cout << (algo() ? "TAK\n" : "NIE\n"); return 0; } |