#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Point{ long long x; long long y;}; struct Car{ Point a; Point b; int number; }; vector<Car> parkFirst, parkSecond; bool comp(Car carA, Car carB){ return carA.a.x < carB.a.x; } Car setSquare(Car car){ if(car.a.x > car.b.x) swap(car.a.x, car.b.x); if(car.a.y > car.b.y) swap(car.a.y, car.b.y); return car; } int getHeight(Car car){ return car.b.y - car.a.y; } int main() { int n; cin >> n; while(n--){ parkFirst.resize(0); parkSecond.resize(0); long long cars, height; cin >> cars >> height; for(int i = 0; i < cars; i++){ Car car; cin >> car.a.x >> car.a.y >> car.b.x >> car.b.y; car.number = i; parkFirst.push_back(setSquare(car)); } for(int i = 0; i < cars; i++){ Car car; cin >> car.a.x >> car.a.y >> car.b.x >> car.b.y; car.number = i; parkSecond.push_back(setSquare(car)); } sort(parkFirst.begin(), parkFirst.end(), comp); sort(parkSecond.begin(), parkSecond.end(), comp); for(int i = 0; i <= cars; i++){ if(i == cars){cout << "TAK\n"; break;} for(int l = 0; l < cars; l++){ if(parkFirst[l].number == -1) continue; if(parkSecond[i].number == parkFirst[l].number){parkFirst[l].number = -1; break;} if(getHeight(parkSecond[i]) + getHeight(parkFirst[l]) > height){ cout << "NIE\n"; i = cars+1; break; } } } } 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; struct Point{ long long x; long long y;}; struct Car{ Point a; Point b; int number; }; vector<Car> parkFirst, parkSecond; bool comp(Car carA, Car carB){ return carA.a.x < carB.a.x; } Car setSquare(Car car){ if(car.a.x > car.b.x) swap(car.a.x, car.b.x); if(car.a.y > car.b.y) swap(car.a.y, car.b.y); return car; } int getHeight(Car car){ return car.b.y - car.a.y; } int main() { int n; cin >> n; while(n--){ parkFirst.resize(0); parkSecond.resize(0); long long cars, height; cin >> cars >> height; for(int i = 0; i < cars; i++){ Car car; cin >> car.a.x >> car.a.y >> car.b.x >> car.b.y; car.number = i; parkFirst.push_back(setSquare(car)); } for(int i = 0; i < cars; i++){ Car car; cin >> car.a.x >> car.a.y >> car.b.x >> car.b.y; car.number = i; parkSecond.push_back(setSquare(car)); } sort(parkFirst.begin(), parkFirst.end(), comp); sort(parkSecond.begin(), parkSecond.end(), comp); for(int i = 0; i <= cars; i++){ if(i == cars){cout << "TAK\n"; break;} for(int l = 0; l < cars; l++){ if(parkFirst[l].number == -1) continue; if(parkSecond[i].number == parkFirst[l].number){parkFirst[l].number = -1; break;} if(getHeight(parkSecond[i]) + getHeight(parkFirst[l]) > height){ cout << "NIE\n"; i = cars+1; break; } } } } return 0; } |