#include <cstdio> #include <algorithm> #include <map> #include <set> #include <iostream> #include <cmath> using namespace std; struct car { int posL, posR, toL, toR, height, minHeight; }; int main() { int t, n, height, i, j, tmp, max; int x1, x2, y1, y2; scanf("%d", &t); while(t--) { scanf("%d %d", &n, &height); car * cars = new car[n]; car * c; map<int, int> way; set<int> myset; set<int>::iterator it; for(i = 0; i < n; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); c = &cars[i]; c->posL = x1 < x2 ? x1 : x2; c->posR = x1 < x2 ? x2 : x1; c->height = abs(y1 - y2); tmp = height - c->height; for(j = c->posL; j <= c->posR; ++j) { if(way[j] == 0) { way[j] = tmp; myset.insert(j); } else if(tmp < way[j]) way[j] = tmp; } } for(i = 0; i < n; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); c = &cars[i]; c->toL = x1 < x2 ? x1 : x2; c->toR = x1 < x2 ? x2 : x1; for(j = c->toL; j <= c->toR; ++j) { if(way[j] == 0) { myset.insert(j); way[j] = height; } } } // for(auto& w: way) { // printf("%d = %d\n", w.first, w.second); // } for(i = 0; i < n; ++i) { c = &cars[i]; if(c->posL != c->toL) { // printf("posL: %d posR: %d toL: %d toR: %d height: %d\n", c->posL, c->posR, c->toL, c->toR, c->height); if(c->posL > c->toL) { // do tyłu it = myset.find(c->posL); --it; while (*it != c->toL) { if(way[*it] < c->height) goto end; --it; } } else { // do przodu it = myset.find(c->posR); ++it; while(*it != c->toR) { if(way[*it] < c->height) goto end; ++it; } } } } goto success; end: puts("NIE"); continue; success: puts("TAK"); } 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | #include <cstdio> #include <algorithm> #include <map> #include <set> #include <iostream> #include <cmath> using namespace std; struct car { int posL, posR, toL, toR, height, minHeight; }; int main() { int t, n, height, i, j, tmp, max; int x1, x2, y1, y2; scanf("%d", &t); while(t--) { scanf("%d %d", &n, &height); car * cars = new car[n]; car * c; map<int, int> way; set<int> myset; set<int>::iterator it; for(i = 0; i < n; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); c = &cars[i]; c->posL = x1 < x2 ? x1 : x2; c->posR = x1 < x2 ? x2 : x1; c->height = abs(y1 - y2); tmp = height - c->height; for(j = c->posL; j <= c->posR; ++j) { if(way[j] == 0) { way[j] = tmp; myset.insert(j); } else if(tmp < way[j]) way[j] = tmp; } } for(i = 0; i < n; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); c = &cars[i]; c->toL = x1 < x2 ? x1 : x2; c->toR = x1 < x2 ? x2 : x1; for(j = c->toL; j <= c->toR; ++j) { if(way[j] == 0) { myset.insert(j); way[j] = height; } } } // for(auto& w: way) { // printf("%d = %d\n", w.first, w.second); // } for(i = 0; i < n; ++i) { c = &cars[i]; if(c->posL != c->toL) { // printf("posL: %d posR: %d toL: %d toR: %d height: %d\n", c->posL, c->posR, c->toL, c->toR, c->height); if(c->posL > c->toL) { // do tyłu it = myset.find(c->posL); --it; while (*it != c->toL) { if(way[*it] < c->height) goto end; --it; } } else { // do przodu it = myset.find(c->posR); ++it; while(*it != c->toR) { if(way[*it] < c->height) goto end; ++it; } } } } goto success; end: puts("NIE"); continue; success: puts("TAK"); } return(0); } |