#include <iostream> #include <bits/stdc++.h> #include <vector> #include <fstream> #include <string> using namespace std; int getWsum(std::vector<int> a, std::vector<int> w, int t) { int sum(0); for (int i=0; i< a.size(); i++) if (a.at(i)==t) { sum+=w.at(i); } return sum; } double getDiv(std::vector<int> a, std::vector<int> w, double avr) { double div(0); for (int i=0; i< a.size(); i++) { div+=std::abs(avr- a.at(i))*w.at(i); } return div; } int main() { int t; cin >> t; for (int j=0; j<t; j++) { int n; cin >> n; std::vector<int> l, a, b; int x,y,z; for (int i=0; i<n; i++) { cin >> x >> y >> z; l.push_back(x); a.push_back(y); b.push_back(z); } uint64_t r1(0), r2(0), r3(0); for (int i=0; i<n; i++) { r1+=l.at(i)*a.at(i); r2+=l.at(i)*b.at(i); r3+=l.at(i); } if (r1!=r2) { cout << "NIE" << endl; continue; } int amin = *(std::min_element(a.begin(), a.end())); int bmin = *(std::min_element(b.begin(), b.end())); int amax = *(std::max_element(a.begin(), a.end())); int bmax = *(std::max_element(b.begin(), b.end())); if (bmax > amax) { cout << "NIE" << endl; continue; } if (bmin < amin) { cout << "NIE" << endl; continue; } if (bmax == amax && getWsum(a,l,bmax) < getWsum(b,l,bmax)) { cout << ("NIE"); continue; } if (bmin == amin && getWsum(a,l,bmin) < getWsum(b,l,bmin)) { cout << "NIE" << endl; continue; } if (getDiv(a,l,r1/r3) < getDiv(b,l,r1/r3)) { cout << "NIE" << endl; continue; } cout << "TAK" << endl; } 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 | #include <iostream> #include <bits/stdc++.h> #include <vector> #include <fstream> #include <string> using namespace std; int getWsum(std::vector<int> a, std::vector<int> w, int t) { int sum(0); for (int i=0; i< a.size(); i++) if (a.at(i)==t) { sum+=w.at(i); } return sum; } double getDiv(std::vector<int> a, std::vector<int> w, double avr) { double div(0); for (int i=0; i< a.size(); i++) { div+=std::abs(avr- a.at(i))*w.at(i); } return div; } int main() { int t; cin >> t; for (int j=0; j<t; j++) { int n; cin >> n; std::vector<int> l, a, b; int x,y,z; for (int i=0; i<n; i++) { cin >> x >> y >> z; l.push_back(x); a.push_back(y); b.push_back(z); } uint64_t r1(0), r2(0), r3(0); for (int i=0; i<n; i++) { r1+=l.at(i)*a.at(i); r2+=l.at(i)*b.at(i); r3+=l.at(i); } if (r1!=r2) { cout << "NIE" << endl; continue; } int amin = *(std::min_element(a.begin(), a.end())); int bmin = *(std::min_element(b.begin(), b.end())); int amax = *(std::max_element(a.begin(), a.end())); int bmax = *(std::max_element(b.begin(), b.end())); if (bmax > amax) { cout << "NIE" << endl; continue; } if (bmin < amin) { cout << "NIE" << endl; continue; } if (bmax == amax && getWsum(a,l,bmax) < getWsum(b,l,bmax)) { cout << ("NIE"); continue; } if (bmin == amin && getWsum(a,l,bmin) < getWsum(b,l,bmin)) { cout << "NIE" << endl; continue; } if (getDiv(a,l,r1/r3) < getDiv(b,l,r1/r3)) { cout << "NIE" << endl; continue; } cout << "TAK" << endl; } return 0; } |