#include <cstdio> #include <vector> #include <cmath> using int64 = long long; bool first_law_of_thermodynamics( const std::vector<std::pair<int64, int64>>& A, const std::vector<std::pair<int64, int64>>& B) { int64 heat = 0LL; for (const auto& p : A) { heat += p.first * p.second; } for (const auto& p : B) { heat -= p.first * p.second; } return heat == 0; } bool second_law_of_thermodynamics( const std::vector<std::pair<int64, int64>>& A, const std::vector<std::pair<int64, int64>>& B) { double entropy = 0.0; for (const auto& p : A) { entropy -= log((double)p.first) * (double)p.second; } for (const auto& p : B) { entropy += log((double)p.first) * (double)p.second; } return entropy >= 0.0; } bool test_case() { int n; scanf("%d", &n); std::vector<std::pair<int64, int64>> S(n), T(n); for (int i = 0; i < n; i++) { int l, a, b; scanf("%d %d %d", &l, &a, &b); S[i] = std::make_pair(a, l); T[i] = std::make_pair(b, l); } if (!first_law_of_thermodynamics(S, T)) { return false; } if (!second_law_of_thermodynamics(S, T)) { return false; } return true; } int main() { int t; scanf("%d", &t); while (t--) { if (test_case()) { printf("TAK\n"); } else { printf("NIE\n"); } } }
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 | #include <cstdio> #include <vector> #include <cmath> using int64 = long long; bool first_law_of_thermodynamics( const std::vector<std::pair<int64, int64>>& A, const std::vector<std::pair<int64, int64>>& B) { int64 heat = 0LL; for (const auto& p : A) { heat += p.first * p.second; } for (const auto& p : B) { heat -= p.first * p.second; } return heat == 0; } bool second_law_of_thermodynamics( const std::vector<std::pair<int64, int64>>& A, const std::vector<std::pair<int64, int64>>& B) { double entropy = 0.0; for (const auto& p : A) { entropy -= log((double)p.first) * (double)p.second; } for (const auto& p : B) { entropy += log((double)p.first) * (double)p.second; } return entropy >= 0.0; } bool test_case() { int n; scanf("%d", &n); std::vector<std::pair<int64, int64>> S(n), T(n); for (int i = 0; i < n; i++) { int l, a, b; scanf("%d %d %d", &l, &a, &b); S[i] = std::make_pair(a, l); T[i] = std::make_pair(b, l); } if (!first_law_of_thermodynamics(S, T)) { return false; } if (!second_law_of_thermodynamics(S, T)) { return false; } return true; } int main() { int t; scanf("%d", &t); while (t--) { if (test_case()) { printf("TAK\n"); } else { printf("NIE\n"); } } } |