///*** Naglowki Piotra Stanczyka #include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <algorithm> #include <ctime> #include <fstream> using namespace std; typedef vector<int> VI; typedef long long LL; #define FOR(x, b, e) for(int x=b; x<=(e); ++x) #define FORD(x, b, e) for(int x=b; x>=(e); x--) #define REP(x, n) for(int x=0; x<(n); ++x) #define VAR(v,n) typeof(n) v=(n) #define ALL(c) c.begin(),c.end() #define SIZE(x) (int)x.size() #define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i) #define PB push_back #define ST first #define ND second const int size = 100000; const int INF = 1000000300; struct H { int id1, id2, h; }; struct P { int x, h, id; }; vector <P> perm1, perm2; vector <H> heights, T(size); bool sortPreferencesH(H x, H y) { return x.h < y.h || (x.h == y.h && x.id1 < y.id1); } bool sortPreferencesP(P a, P b) { return a.x < b.x ||(a.x == b.x && a.h < b.h); } int main() { ios_base::sync_with_stdio(0); int t, n, w, x1, x2, y1, y2; P pr; H wys; cin>>t; REP(x, t) { cin>>n>>w; perm1.clear(); perm2.clear(); heights.clear(); FOR(i, 1, n) { cin>>x1>>y1>>x2>>y2; //P.x = min(x1, x2); //P.h = abs() if(x1 < x2)pr.x = x1; else pr.x = x2; if(y1 < y2)pr.h = y2-y1; else pr.h = y1-y2; pr.id = i; perm1.PB(pr); } FOR(i, 1, n) { cin>>x1>>y1>>x2>>y2; //P.x = min(x1, x2); //P.h = abs() if(x1 < x2)pr.x = x1; else pr.x = x2; if(y1 < y2)pr.h = y2-y1; else pr.h = y1-y2; pr.id = i; T[i].h = pr.h; perm2.PB(pr); } sort(perm1.begin(), perm1.end(), sortPreferencesP); sort(perm2.begin(), perm2.end(), sortPreferencesP); /*cout<<"sorted perm1 id x h:\n"; FOREACH(i, perm1)cout<<i->id<<' '<<i->x<<' '<<i->h<<endl; cout<<"sorted perm2 id x h:\n"; FOREACH(i, perm2)cout<<i->id<<' '<<i->x<<' '<<i->h<<endl;*/ FOR(i, 0, n-1)T[perm1[i].id].id1 = i; FOR(i, 0, n-1)T[perm2[i].id].id2 = i; //cout<<"T i id1 id2 h:\n"; //FOR(i, 1, n)cout<<i<<' '<<T[i].id1<<' '<<T[i].id2<<' '<<T[i].h<<endl; bool check = true; FOR(i, 1, n)FOR(j, 1, n) { if((T[i].id1-T[j].id1)*(T[i].id2-T[j].id2) < 0 && T[i].h+T[j].h > w) { check = false; break; } } /*FOR(i, 1, n) { heights.PB(T[i]); } sort(heights.begin(), heights.end(), sortPreferencesH); cout<<"sorted heights\nid1 id2 h:\n"; FOREACH(i, heights)cout<<i->id1<<' '<<i->id2<<' '<<i->h<<endl; //int k, l; FORD(i, n-1, 1) { //k = heights[i].id1; //l = heights[i].id2; if(heights[i].h + heights[i-1].h > w && (heights[i].id1-heights[i-1].id1)*(heights[i].id2-heights[i-1].id2) < 0) { check = false; break; } }*/ if(check)cout<<"TAK\n"; else cout<<"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 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 152 153 154 155 156 157 158 159 160 161 | ///*** Naglowki Piotra Stanczyka #include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <algorithm> #include <ctime> #include <fstream> using namespace std; typedef vector<int> VI; typedef long long LL; #define FOR(x, b, e) for(int x=b; x<=(e); ++x) #define FORD(x, b, e) for(int x=b; x>=(e); x--) #define REP(x, n) for(int x=0; x<(n); ++x) #define VAR(v,n) typeof(n) v=(n) #define ALL(c) c.begin(),c.end() #define SIZE(x) (int)x.size() #define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i) #define PB push_back #define ST first #define ND second const int size = 100000; const int INF = 1000000300; struct H { int id1, id2, h; }; struct P { int x, h, id; }; vector <P> perm1, perm2; vector <H> heights, T(size); bool sortPreferencesH(H x, H y) { return x.h < y.h || (x.h == y.h && x.id1 < y.id1); } bool sortPreferencesP(P a, P b) { return a.x < b.x ||(a.x == b.x && a.h < b.h); } int main() { ios_base::sync_with_stdio(0); int t, n, w, x1, x2, y1, y2; P pr; H wys; cin>>t; REP(x, t) { cin>>n>>w; perm1.clear(); perm2.clear(); heights.clear(); FOR(i, 1, n) { cin>>x1>>y1>>x2>>y2; //P.x = min(x1, x2); //P.h = abs() if(x1 < x2)pr.x = x1; else pr.x = x2; if(y1 < y2)pr.h = y2-y1; else pr.h = y1-y2; pr.id = i; perm1.PB(pr); } FOR(i, 1, n) { cin>>x1>>y1>>x2>>y2; //P.x = min(x1, x2); //P.h = abs() if(x1 < x2)pr.x = x1; else pr.x = x2; if(y1 < y2)pr.h = y2-y1; else pr.h = y1-y2; pr.id = i; T[i].h = pr.h; perm2.PB(pr); } sort(perm1.begin(), perm1.end(), sortPreferencesP); sort(perm2.begin(), perm2.end(), sortPreferencesP); /*cout<<"sorted perm1 id x h:\n"; FOREACH(i, perm1)cout<<i->id<<' '<<i->x<<' '<<i->h<<endl; cout<<"sorted perm2 id x h:\n"; FOREACH(i, perm2)cout<<i->id<<' '<<i->x<<' '<<i->h<<endl;*/ FOR(i, 0, n-1)T[perm1[i].id].id1 = i; FOR(i, 0, n-1)T[perm2[i].id].id2 = i; //cout<<"T i id1 id2 h:\n"; //FOR(i, 1, n)cout<<i<<' '<<T[i].id1<<' '<<T[i].id2<<' '<<T[i].h<<endl; bool check = true; FOR(i, 1, n)FOR(j, 1, n) { if((T[i].id1-T[j].id1)*(T[i].id2-T[j].id2) < 0 && T[i].h+T[j].h > w) { check = false; break; } } /*FOR(i, 1, n) { heights.PB(T[i]); } sort(heights.begin(), heights.end(), sortPreferencesH); cout<<"sorted heights\nid1 id2 h:\n"; FOREACH(i, heights)cout<<i->id1<<' '<<i->id2<<' '<<i->h<<endl; //int k, l; FORD(i, n-1, 1) { //k = heights[i].id1; //l = heights[i].id2; if(heights[i].h + heights[i-1].h > w && (heights[i].id1-heights[i-1].id1)*(heights[i].id2-heights[i-1].id2) < 0) { check = false; break; } }*/ if(check)cout<<"TAK\n"; else cout<<"NIE\n"; } return 0; } |