// Mateusz Kurek, PA 2014 // 3B PAR #include<cstdio> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> #include<string> #include<list> #include<deque> #include<map> #include<set> #include<queue> #include<stack> #include<utility> #include<sstream> #include<cstring> #include <string> //#include <iostream> using namespace std; #define REP(i,v)for(int i=0;i<(v);++i) #define FOR(i,x,v)for(int i=x;i<=(v);++i) #define FORD(i,x,v)for(int i=x;i>=(v);--i) #define VAR(v,n) __typeof(n) v = (n) #define FOREACH(i,c) for(VAR(i,(c).begin()); i != (c).end(); ++i) #define ALL(c) (c).begin(), c.end() #define PB push_back #define SZ size #define MP make_pair #define FI first #define SE second #define CL clear() #define RS resize #define INFTY 1000000001 #define EPS 10e-9 #define SIZE(x) ((int)(x).size()) typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<bool> VB; typedef pair<int,int> PII; typedef long long LL; typedef vector<string> VS; void show(PII p) {printf("(%d %d)\n",p.FI,p.SE);} void show(VI e) {REP(i,SIZE(e)) printf("%d ",e[i]); printf("\n");} void show(vector<PII> e) {REP(i,SIZE(e)) printf("(%d %d) ",e[i].FI,e[i].SE); printf("\n");} void show(VS e) {REP(i,SIZE(e)) printf("%s\n",e[i].c_str());} void show(VVI e) {REP(i,SIZE(e)) show(e[i]);} #define MAXN 500001 int x_start[MAXN], x_end[MAXN], y_start[MAXN], y_end[MAXN], h[MAXN], order_start[MAXN], order_end[MAXN], order_h[MAXN]; bool h_sort(int i, int j){ return h[i] > h[j]; } bool start_sort(int i, int j){ if(x_start[i] == x_start[j]){ return y_start[i] < y_start[j]; } return x_start[i] < x_start[j]; } bool end_sort(int i, int j){ if(x_end[i] == x_end[j]){ return y_end[i] < y_end[j]; } return x_end[i] < x_end[j]; } void test(){ int t, n, w, x1, x2, y1, y2; scanf("%d %d", &n, &w); REP(j, n){ scanf("%d %d %d %d", &x1, &y1, &x2, &y2); x_start[j] = x1; y_start[j] = y1; h[j] = abs(y2 - y1); order_start[j] = j; order_h[j] = j; } REP(j, n){ scanf("%d %d %d %d", &x1, &y1, &x2, &y2); x_end[j] = x1; y_end[j] = y1; order_end[j] = j; } sort(order_start, order_start + n, start_sort); sort(order_end, order_end + n, end_sort); sort(order_h, order_h + n, h_sort); REP(j, n){ x_start[order_start[j]] = j; x_end[order_end[j]] = j; } // VI x_startv(x_start, x_start+n), x_endv(x_end, x_end+n), hv(h, h+n), osv(order_start, order_start+n), oev(order_end, order_end+n), ohv(order_h, order_h+n); // printf("start order:\n"); // show(osv); // printf("end order:\n"); // show(oev); // printf("start position of car of index i: \n"); // show(x_startv); // printf("end position of car of index i: \n"); // show(x_endv); // printf("height of car of index i: \n"); // show(hv); // printf("h order:\n"); // show(ohv); REP(j, n){ int pos_start = x_start[j], pos_end = x_end[j], hh = h[j], max_another_h = w - hh, k = 0, item; while(k < n){ item = order_h[k]; if(h[item] <= max_another_h){ break; } if(pos_start < x_start[item] && pos_end > x_end[item]){ printf("NIE\n"); return; } k++; } } printf("TAK\n"); } int main() { int t; scanf("%d", &t); REP(i, t){ test(); } }
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | // Mateusz Kurek, PA 2014 // 3B PAR #include<cstdio> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> #include<string> #include<list> #include<deque> #include<map> #include<set> #include<queue> #include<stack> #include<utility> #include<sstream> #include<cstring> #include <string> //#include <iostream> using namespace std; #define REP(i,v)for(int i=0;i<(v);++i) #define FOR(i,x,v)for(int i=x;i<=(v);++i) #define FORD(i,x,v)for(int i=x;i>=(v);--i) #define VAR(v,n) __typeof(n) v = (n) #define FOREACH(i,c) for(VAR(i,(c).begin()); i != (c).end(); ++i) #define ALL(c) (c).begin(), c.end() #define PB push_back #define SZ size #define MP make_pair #define FI first #define SE second #define CL clear() #define RS resize #define INFTY 1000000001 #define EPS 10e-9 #define SIZE(x) ((int)(x).size()) typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<bool> VB; typedef pair<int,int> PII; typedef long long LL; typedef vector<string> VS; void show(PII p) {printf("(%d %d)\n",p.FI,p.SE);} void show(VI e) {REP(i,SIZE(e)) printf("%d ",e[i]); printf("\n");} void show(vector<PII> e) {REP(i,SIZE(e)) printf("(%d %d) ",e[i].FI,e[i].SE); printf("\n");} void show(VS e) {REP(i,SIZE(e)) printf("%s\n",e[i].c_str());} void show(VVI e) {REP(i,SIZE(e)) show(e[i]);} #define MAXN 500001 int x_start[MAXN], x_end[MAXN], y_start[MAXN], y_end[MAXN], h[MAXN], order_start[MAXN], order_end[MAXN], order_h[MAXN]; bool h_sort(int i, int j){ return h[i] > h[j]; } bool start_sort(int i, int j){ if(x_start[i] == x_start[j]){ return y_start[i] < y_start[j]; } return x_start[i] < x_start[j]; } bool end_sort(int i, int j){ if(x_end[i] == x_end[j]){ return y_end[i] < y_end[j]; } return x_end[i] < x_end[j]; } void test(){ int t, n, w, x1, x2, y1, y2; scanf("%d %d", &n, &w); REP(j, n){ scanf("%d %d %d %d", &x1, &y1, &x2, &y2); x_start[j] = x1; y_start[j] = y1; h[j] = abs(y2 - y1); order_start[j] = j; order_h[j] = j; } REP(j, n){ scanf("%d %d %d %d", &x1, &y1, &x2, &y2); x_end[j] = x1; y_end[j] = y1; order_end[j] = j; } sort(order_start, order_start + n, start_sort); sort(order_end, order_end + n, end_sort); sort(order_h, order_h + n, h_sort); REP(j, n){ x_start[order_start[j]] = j; x_end[order_end[j]] = j; } // VI x_startv(x_start, x_start+n), x_endv(x_end, x_end+n), hv(h, h+n), osv(order_start, order_start+n), oev(order_end, order_end+n), ohv(order_h, order_h+n); // printf("start order:\n"); // show(osv); // printf("end order:\n"); // show(oev); // printf("start position of car of index i: \n"); // show(x_startv); // printf("end position of car of index i: \n"); // show(x_endv); // printf("height of car of index i: \n"); // show(hv); // printf("h order:\n"); // show(ohv); REP(j, n){ int pos_start = x_start[j], pos_end = x_end[j], hh = h[j], max_another_h = w - hh, k = 0, item; while(k < n){ item = order_h[k]; if(h[item] <= max_another_h){ break; } if(pos_start < x_start[item] && pos_end > x_end[item]){ printf("NIE\n"); return; } k++; } } printf("TAK\n"); } int main() { int t; scanf("%d", &t); REP(i, t){ test(); } } |