#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <list>
using namespace std;
const int N_MAX = 50000;
typedef struct {
int x1;
int x2;
int y1;
int y2;
int id;
} dane;
bool compare(const dane& a, const dane& b) {
if (a.x1 != b.x1) {
return a.x1 < b.x1;
} else {
return a.id < b.id;
}
}
void exchange(int &a, int &b) {
int pom = a;
a = b;
b = pom;
}
int main() {
int t;
scanf("%d\n", &t);
for (int tId = 0; tId < t; ++tId) {
int n, w;
scanf("%d %d\n", &n, &w);
list<dane> pocz, kon;
for (int i = 1; i <= n; ++i) {
dane pkt;
pkt.id = i;
scanf("%d %d %d %d\n", &pkt.x1, &pkt.y1, &pkt.x2, &pkt.y2);
if (pkt.x1 > pkt.x2) exchange(pkt.x1, pkt.x2);
if (pkt.y1 > pkt.y2) exchange(pkt.y1, pkt.y2);
pocz.push_back(pkt);
}
for (int i = 1; i <= n; ++i) {
dane pkt;
pkt.id = i;
scanf("%d %d %d %d\n", &pkt.x1, &pkt.y1, &pkt.x2, &pkt.y2);
if (pkt.x1 > pkt.x2) exchange(pkt.x1, pkt.x2);
if (pkt.y1 > pkt.y2) exchange(pkt.y1, pkt.y2);
kon.push_back(pkt);
}
pocz.sort(compare);
kon.sort(compare);
list<dane>::iterator i, j;
bool result = true;
for (i = kon.begin(); i != kon.end() && result; ++i) {
j = pocz.begin();
while (i->id != j->id && result) {
int h = i->y2 - i->y1 + j->y2 - j->y1;
result = h <= w;
++j;
}
if (result) {
pocz.erase(j);
}
}
if (result) 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 | #include <cstdio> #include <cstdlib> #include <algorithm> #include <list> using namespace std; const int N_MAX = 50000; typedef struct { int x1; int x2; int y1; int y2; int id; } dane; bool compare(const dane& a, const dane& b) { if (a.x1 != b.x1) { return a.x1 < b.x1; } else { return a.id < b.id; } } void exchange(int &a, int &b) { int pom = a; a = b; b = pom; } int main() { int t; scanf("%d\n", &t); for (int tId = 0; tId < t; ++tId) { int n, w; scanf("%d %d\n", &n, &w); list<dane> pocz, kon; for (int i = 1; i <= n; ++i) { dane pkt; pkt.id = i; scanf("%d %d %d %d\n", &pkt.x1, &pkt.y1, &pkt.x2, &pkt.y2); if (pkt.x1 > pkt.x2) exchange(pkt.x1, pkt.x2); if (pkt.y1 > pkt.y2) exchange(pkt.y1, pkt.y2); pocz.push_back(pkt); } for (int i = 1; i <= n; ++i) { dane pkt; pkt.id = i; scanf("%d %d %d %d\n", &pkt.x1, &pkt.y1, &pkt.x2, &pkt.y2); if (pkt.x1 > pkt.x2) exchange(pkt.x1, pkt.x2); if (pkt.y1 > pkt.y2) exchange(pkt.y1, pkt.y2); kon.push_back(pkt); } pocz.sort(compare); kon.sort(compare); list<dane>::iterator i, j; bool result = true; for (i = kon.begin(); i != kon.end() && result; ++i) { j = pocz.begin(); while (i->id != j->id && result) { int h = i->y2 - i->y1 + j->y2 - j->y1; result = h <= w; ++j; } if (result) { pocz.erase(j); } } if (result) printf("TAK\n"); else printf("NIE\n"); } } |
English