#include <iostream> #include <vector> #include <climits> int main(){ int tests = 0; std::cin >> tests; for (int k = 0; k < tests; k++) { int kids; bool possible = true; std::cin >> kids; //std::vector<int> volume; std::vector<int> currTemp; std::vector<int> targetTemp; int minCurrTemp = INT_MAX, maxTarTemp = 0; int minTarTemp = minCurrTemp, maxCurrTemp = maxTarTemp; double currtotalratio = 0; double currTempSum = 0; double tarTempSum = 0; double tartotalratio = 0; int currTemp, currVol; for (int h = 0; h < kids; h++) { std::cin >> currVol; //volume.push_back(curr); std::cin >> currTemp; currtotalratio += currTemp * currVol; currTempSum += currTemp; //currTemp.push_back(curr); minCurrTemp = currTemp < minCurrTemp ? currTemp : minCurrTemp; maxCurrTemp = currTemp < maxCurrTemp ? currTemp : maxCurrTemp; std::cin >> currTemp; tarTempSum += currTemp; tartotalratio += currTemp * currVol; //targetTemp.push_back(curr); minTarTemp = currTemp < minTarTemp ? currTemp : minTarTemp; maxTarTemp = currTemp < maxTarTemp ? currTemp : maxTarTemp; } if (minCurrTemp > minTarTemp) possible = false; else if (maxTarTemp > maxCurrTemp) possible = false; else if (currtotalratio / currTempSum != tartotalratio / tarTempSum) possible = false; if (possible) std::cout << "TAK\n"; else std::cout << "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 | #include <iostream> #include <vector> #include <climits> int main(){ int tests = 0; std::cin >> tests; for (int k = 0; k < tests; k++) { int kids; bool possible = true; std::cin >> kids; //std::vector<int> volume; std::vector<int> currTemp; std::vector<int> targetTemp; int minCurrTemp = INT_MAX, maxTarTemp = 0; int minTarTemp = minCurrTemp, maxCurrTemp = maxTarTemp; double currtotalratio = 0; double currTempSum = 0; double tarTempSum = 0; double tartotalratio = 0; int currTemp, currVol; for (int h = 0; h < kids; h++) { std::cin >> currVol; //volume.push_back(curr); std::cin >> currTemp; currtotalratio += currTemp * currVol; currTempSum += currTemp; //currTemp.push_back(curr); minCurrTemp = currTemp < minCurrTemp ? currTemp : minCurrTemp; maxCurrTemp = currTemp < maxCurrTemp ? currTemp : maxCurrTemp; std::cin >> currTemp; tarTempSum += currTemp; tartotalratio += currTemp * currVol; //targetTemp.push_back(curr); minTarTemp = currTemp < minTarTemp ? currTemp : minTarTemp; maxTarTemp = currTemp < maxTarTemp ? currTemp : maxTarTemp; } if (minCurrTemp > minTarTemp) possible = false; else if (maxTarTemp > maxCurrTemp) possible = false; else if (currtotalratio / currTempSum != tartotalratio / tarTempSum) possible = false; if (possible) std::cout << "TAK\n"; else std::cout << "NIE\n"; } } |