#include <iostream> #include <vector> //static const int MAX_N = 131072; static const int MAX_N = 100009;; int mirrors[MAX_N][4]; std::vector<int> nodes[5]; void common(std::vector<int> &in1, std::vector<int> &in2, std::vector<int> &out) { if (in1.empty() || in2.empty()) return; int i=0; int j=0; while (i < in1.size() && j < in1.size()) { if (in1[i] == in2[j]) { out.push_back(in1[i]); i++; j++; } else if (in1[i] < in2[j]) ++i; else ++j; } } void processCase() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d%d%d%d", mirrors[i], mirrors[i]+1, mirrors[i]+2, mirrors[i]+3); for (int i = 0; i < 5; ++i) nodes[i].clear(); int range[4]; for (int i = 0; i < 4; ++i) range[i] = mirrors[0][i]; for (int i = 0; i < n; ++i) { range[0] = std::min(range[0], mirrors[i][0]); range[1] = std::max(range[1], mirrors[i][1]); range[2] = std::min(range[2], mirrors[i][2]); range[3] = std::max(range[3], mirrors[i][3]); } for (int i = 0; i < n; ++i) for (int j = 0; j < 4; ++j) if (mirrors[i][j] == range[j]) nodes[j].push_back(i); common(nodes[0], nodes[1], nodes[4]); nodes[1].clear(); nodes[0].clear(); common(nodes[2], nodes[3], nodes[0]); common(nodes[0], nodes[4], nodes[1]); printf(nodes[1].size() > 0 ? "TAK\n" : "NIE\n"); } int main() { int T; scanf("%d", &T); while (T--) processCase(); 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 | #include <iostream> #include <vector> //static const int MAX_N = 131072; static const int MAX_N = 100009;; int mirrors[MAX_N][4]; std::vector<int> nodes[5]; void common(std::vector<int> &in1, std::vector<int> &in2, std::vector<int> &out) { if (in1.empty() || in2.empty()) return; int i=0; int j=0; while (i < in1.size() && j < in1.size()) { if (in1[i] == in2[j]) { out.push_back(in1[i]); i++; j++; } else if (in1[i] < in2[j]) ++i; else ++j; } } void processCase() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d%d%d%d", mirrors[i], mirrors[i]+1, mirrors[i]+2, mirrors[i]+3); for (int i = 0; i < 5; ++i) nodes[i].clear(); int range[4]; for (int i = 0; i < 4; ++i) range[i] = mirrors[0][i]; for (int i = 0; i < n; ++i) { range[0] = std::min(range[0], mirrors[i][0]); range[1] = std::max(range[1], mirrors[i][1]); range[2] = std::min(range[2], mirrors[i][2]); range[3] = std::max(range[3], mirrors[i][3]); } for (int i = 0; i < n; ++i) for (int j = 0; j < 4; ++j) if (mirrors[i][j] == range[j]) nodes[j].push_back(i); common(nodes[0], nodes[1], nodes[4]); nodes[1].clear(); nodes[0].clear(); common(nodes[2], nodes[3], nodes[0]); common(nodes[0], nodes[4], nodes[1]); printf(nodes[1].size() > 0 ? "TAK\n" : "NIE\n"); } int main() { int T; scanf("%d", &T); while (T--) processCase(); return 0; } |