#include <iostream> #include <fstream> #include <vector> #include <list> #include <limits> #include <algorithm> #include <cstdlib> int n; // liczba samochodow na parkingu int w; // wysokosc parkingu struct Car { int id; int x; int h; // wysokosc }; std::vector<Car> cars1, cars2; struct Order { int id1, id2; }; void read_test(std::istream & str) { int i; int x1, x2, y1, y2; Car car; str >> n >> w; cars1.clear(); cars2.clear(); cars1.reserve(n); cars2.reserve(n); for(i=0 ; i<n ; ++i) { str >> x1 >> y1 >> x2 >> y2; car.id = i; car.x = ((long long)x1 + (long long)x2) / 2; car.h = abs(y2 - y1); cars1.push_back(car); } for(i=0 ; i<n ; ++i) { str >> x1 >> y1 >> x2 >> y2; car.id = i; car.x = ((long long)x1 + (long long)x2) / 2; car.h = abs(y2 - y1); cars2.push_back(car); } } void print(std::vector<Car> & cars) { int i; for(i=0 ; i<cars.size() ; ++i) { Car & c = cars[i]; std::cout << c.id << " " << c.x << " " << c.h << std::endl; } } bool calc() { int a, b, len; Order o; len = cars1.size(); for(a=0 ; a<len ; ++a) { for(b=a+1 ; b<len ; ++b) { Car & ca = cars1[a]; Car & cb = cars1[b]; if( ca.h + cb.h > w ) { if( ca.x < cb.x ) { o.id1 = ca.id; o.id2 = cb.id; } else { o.id1 = cb.id; o.id2 = ca.id; } Car & cca = cars2[o.id1]; Car & ccb = cars2[o.id2]; if( cca.x > ccb.x ) return false; } } } return true; } void read_and_calc(std::istream & str) { int t, i; str >> t; for(i=0 ; i<t ; ++i) { read_test(str); if( calc() ) std::cout << "TAK" << std::endl; else std::cout << "NIE" << std::endl; } } int main() { std::cin.sync_with_stdio(false); read_and_calc(std::cin); }
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | #include <iostream> #include <fstream> #include <vector> #include <list> #include <limits> #include <algorithm> #include <cstdlib> int n; // liczba samochodow na parkingu int w; // wysokosc parkingu struct Car { int id; int x; int h; // wysokosc }; std::vector<Car> cars1, cars2; struct Order { int id1, id2; }; void read_test(std::istream & str) { int i; int x1, x2, y1, y2; Car car; str >> n >> w; cars1.clear(); cars2.clear(); cars1.reserve(n); cars2.reserve(n); for(i=0 ; i<n ; ++i) { str >> x1 >> y1 >> x2 >> y2; car.id = i; car.x = ((long long)x1 + (long long)x2) / 2; car.h = abs(y2 - y1); cars1.push_back(car); } for(i=0 ; i<n ; ++i) { str >> x1 >> y1 >> x2 >> y2; car.id = i; car.x = ((long long)x1 + (long long)x2) / 2; car.h = abs(y2 - y1); cars2.push_back(car); } } void print(std::vector<Car> & cars) { int i; for(i=0 ; i<cars.size() ; ++i) { Car & c = cars[i]; std::cout << c.id << " " << c.x << " " << c.h << std::endl; } } bool calc() { int a, b, len; Order o; len = cars1.size(); for(a=0 ; a<len ; ++a) { for(b=a+1 ; b<len ; ++b) { Car & ca = cars1[a]; Car & cb = cars1[b]; if( ca.h + cb.h > w ) { if( ca.x < cb.x ) { o.id1 = ca.id; o.id2 = cb.id; } else { o.id1 = cb.id; o.id2 = ca.id; } Car & cca = cars2[o.id1]; Car & ccb = cars2[o.id2]; if( cca.x > ccb.x ) return false; } } } return true; } void read_and_calc(std::istream & str) { int t, i; str >> t; for(i=0 ; i<t ; ++i) { read_test(str); if( calc() ) std::cout << "TAK" << std::endl; else std::cout << "NIE" << std::endl; } } int main() { std::cin.sync_with_stdio(false); read_and_calc(std::cin); } |