#include <cstdio>
#include <algorithm>
using namespace std;
int t;
class par {
public:
int f;
int s;
int dex;
};
bool comp (par a, par b) {
return a.f<b.f;
}
int min_fz (int a) {
int b=1;
while (a>b) b*=2;
if (a==b) return a;
else return b;
}
bool dyi() {
par tab[50007], bat[50007];
int pos[50007][2];
int hi[100007];
int a, b, c, d, n, w;
scanf ("%d%d", &n, &w);
for (int i=0; i<n; ++i) {
scanf ("%d%d%d%d", &a, &b, &c, &d);
if (a>c) swap (a, c);
if (b>d) swap (b, d);
tab[i].f=a;
tab[i].s=d-b;
tab[i].dex=i;
//printf ("par (%d, %d, %d)\n", tab[i].f, tab[i].s, tab[i].dex);
}
sort (tab, tab+n, comp);
for (int i=0; i<n; ++i) {
scanf ("%d%d%d%d", &a, &b, &c, &d);
if (a>c) swap (a, c);
if (b>d) swap (b, d);
bat[i].f=a;
bat[i].s=d-b;
bat[i].dex=i;
}
sort (bat, bat+n, comp);
for (int i=0; i<n; ++i) {
pos[bat[i].dex][1]=i;
pos[tab[i].dex][0]=i;
}
for (int i=0; i<n; ++i) {
for (int j=pos[bat[i].dex][0]; j>i; --j) {
//printf ("%d %d\n", tab[j].s, tab[j-1].s);
if (tab[j].s+tab[j-1].s>w) return 0;
else {
swap (pos[tab[j].dex][0], pos[tab[j-1].dex][0]);
swap (tab[j], tab[j-1]);
}
}
}
return 1;
}
int main () {
scanf ("%d", &t);
bool wyt;
for (int i=0; i<t; ++i) {
wyt=dyi();
if (wyt) printf ("TAK\n");
else printf ("NIE\n");
}
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 | #include <cstdio> #include <algorithm> using namespace std; int t; class par { public: int f; int s; int dex; }; bool comp (par a, par b) { return a.f<b.f; } int min_fz (int a) { int b=1; while (a>b) b*=2; if (a==b) return a; else return b; } bool dyi() { par tab[50007], bat[50007]; int pos[50007][2]; int hi[100007]; int a, b, c, d, n, w; scanf ("%d%d", &n, &w); for (int i=0; i<n; ++i) { scanf ("%d%d%d%d", &a, &b, &c, &d); if (a>c) swap (a, c); if (b>d) swap (b, d); tab[i].f=a; tab[i].s=d-b; tab[i].dex=i; //printf ("par (%d, %d, %d)\n", tab[i].f, tab[i].s, tab[i].dex); } sort (tab, tab+n, comp); for (int i=0; i<n; ++i) { scanf ("%d%d%d%d", &a, &b, &c, &d); if (a>c) swap (a, c); if (b>d) swap (b, d); bat[i].f=a; bat[i].s=d-b; bat[i].dex=i; } sort (bat, bat+n, comp); for (int i=0; i<n; ++i) { pos[bat[i].dex][1]=i; pos[tab[i].dex][0]=i; } for (int i=0; i<n; ++i) { for (int j=pos[bat[i].dex][0]; j>i; --j) { //printf ("%d %d\n", tab[j].s, tab[j-1].s); if (tab[j].s+tab[j-1].s>w) return 0; else { swap (pos[tab[j].dex][0], pos[tab[j-1].dex][0]); swap (tab[j], tab[j-1]); } } } return 1; } int main () { scanf ("%d", &t); bool wyt; for (int i=0; i<t; ++i) { wyt=dyi(); if (wyt) printf ("TAK\n"); else printf ("NIE\n"); } return 0; } |
polski