#include<iostream> #include<cstdlib> #include<vector> #include<algorithm> #include<cmath> using namespace std; struct sam { int wys; int x_start; int x_end; }; bool porown(const sam& a, const sam& b) { return a.wys > b.wys; } int main() { int t; cin>>t; for(int i = 0; i < t; i++) { int n; int rozm; //cin >> n >> rozm; scanf("%d%d%",&n,&rozm); vector<sam> parking(n); for(int i = 0; i < n; i ++) { int x1, y1, x2, y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); //cin >>x1>>y1>>x2>> y2; parking[i].x_start = x1< x2 ?x1:x2; parking[i].wys =abs(y1 - y2); } for(int i = 0; i < n; i ++) { int x1, y1, x2, y2; //cin >>x1>>y1>>x2>> y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); parking[i].x_end = x1< x2 ?x1:x2; } sort(parking.begin(),parking.end(),porown); bool Nope = false; for(int i = 0; i < n && !Nope; i ++) { //cout << parking[i].wys << endl; for(int j = i + 1; j < n; j ++) { if( parking[i].wys + parking[j].wys > rozm ) { bool pocz = parking[i].x_start < parking[j].x_start; bool end = parking[i].x_end < parking[j].x_end; if( pocz != end) { Nope = true; break; } } else { break; } } } if(Nope) { printf("NIE\n"); //cout<<"NIE"<<endl; } else { printf("TAK\n"); //cout<<"TAK"<<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 | #include<iostream> #include<cstdlib> #include<vector> #include<algorithm> #include<cmath> using namespace std; struct sam { int wys; int x_start; int x_end; }; bool porown(const sam& a, const sam& b) { return a.wys > b.wys; } int main() { int t; cin>>t; for(int i = 0; i < t; i++) { int n; int rozm; //cin >> n >> rozm; scanf("%d%d%",&n,&rozm); vector<sam> parking(n); for(int i = 0; i < n; i ++) { int x1, y1, x2, y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); //cin >>x1>>y1>>x2>> y2; parking[i].x_start = x1< x2 ?x1:x2; parking[i].wys =abs(y1 - y2); } for(int i = 0; i < n; i ++) { int x1, y1, x2, y2; //cin >>x1>>y1>>x2>> y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); parking[i].x_end = x1< x2 ?x1:x2; } sort(parking.begin(),parking.end(),porown); bool Nope = false; for(int i = 0; i < n && !Nope; i ++) { //cout << parking[i].wys << endl; for(int j = i + 1; j < n; j ++) { if( parking[i].wys + parking[j].wys > rozm ) { bool pocz = parking[i].x_start < parking[j].x_start; bool end = parking[i].x_end < parking[j].x_end; if( pocz != end) { Nope = true; break; } } else { break; } } } if(Nope) { printf("NIE\n"); //cout<<"NIE"<<endl; } else { printf("TAK\n"); //cout<<"TAK"<<endl; } } return 0; } |