#include <cstdio> #include <vector> class Car { public: int id, bx, by, ex, ey, w, h; Car(int id, int x, int y, int w, int h): id(id), bx(x), ex(x), by(y), ey(y), w(w), h(h) {} bool isBeforeOnBegin(Car &b) { return bx + w <= b.bx; } bool isBeforeOnEnd(Car &b) { return ex + w <= b.ex; } bool isCrossing(Car &b) { return (isBeforeOnBegin(b) && b.isBeforeOnEnd(*this)) || (b.isBeforeOnBegin(*this) && isBeforeOnEnd(b)); } bool canCross(Car &b, int height) { return h + b.h <= height; } }; void readParkingMovement(std::vector<Car> &cars, int &height) { int n, x1, y1, x2, y2; scanf("%d", &n); scanf("%d", &height); cars.clear(); cars.reserve(n); for(int i = 0; i < n; ++i) { scanf("%d", &x1); scanf("%d", &y1); scanf("%d", &x2); scanf("%d", &y2); cars.push_back(Car(i, x1, y1, x2 - x1, y2 - y1)); } for(int i = 0; i < n; ++i) { scanf("%d", &x1); scanf("%d", &y1); scanf("%d", &x2); scanf("%d", &y2); cars[i].ex = x1; cars[i].ey = y1; } } bool quadraticSolution(std::vector<Car> &cars, int height) { for (std::vector<Car>::iterator it = cars.begin(); it != cars.end(); it++) { for(std::vector<Car>::iterator it2 = it + 1; it2 != cars.end(); it2++) { if (it->isCrossing(*it2) && !it->canCross(*it2, height)){ return false; } } } return true; } int main() { std::vector<Car> cars; int height, t; scanf("%d", &t); for (int i = 0; i < t; ++i) { readParkingMovement(cars, height); if (quadraticSolution(cars, height)) { printf("TAK\n"); } else { printf("NIE\n"); } } }
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 | #include <cstdio> #include <vector> class Car { public: int id, bx, by, ex, ey, w, h; Car(int id, int x, int y, int w, int h): id(id), bx(x), ex(x), by(y), ey(y), w(w), h(h) {} bool isBeforeOnBegin(Car &b) { return bx + w <= b.bx; } bool isBeforeOnEnd(Car &b) { return ex + w <= b.ex; } bool isCrossing(Car &b) { return (isBeforeOnBegin(b) && b.isBeforeOnEnd(*this)) || (b.isBeforeOnBegin(*this) && isBeforeOnEnd(b)); } bool canCross(Car &b, int height) { return h + b.h <= height; } }; void readParkingMovement(std::vector<Car> &cars, int &height) { int n, x1, y1, x2, y2; scanf("%d", &n); scanf("%d", &height); cars.clear(); cars.reserve(n); for(int i = 0; i < n; ++i) { scanf("%d", &x1); scanf("%d", &y1); scanf("%d", &x2); scanf("%d", &y2); cars.push_back(Car(i, x1, y1, x2 - x1, y2 - y1)); } for(int i = 0; i < n; ++i) { scanf("%d", &x1); scanf("%d", &y1); scanf("%d", &x2); scanf("%d", &y2); cars[i].ex = x1; cars[i].ey = y1; } } bool quadraticSolution(std::vector<Car> &cars, int height) { for (std::vector<Car>::iterator it = cars.begin(); it != cars.end(); it++) { for(std::vector<Car>::iterator it2 = it + 1; it2 != cars.end(); it2++) { if (it->isCrossing(*it2) && !it->canCross(*it2, height)){ return false; } } } return true; } int main() { std::vector<Car> cars; int height, t; scanf("%d", &t); for (int i = 0; i < t; ++i) { readParkingMovement(cars, height); if (quadraticSolution(cars, height)) { printf("TAK\n"); } else { printf("NIE\n"); } } } |