#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using dd = double;
using namespace std;
bool findHottest(vector<vector<dd>>& cups)
{
dd max1 = 0, max2 = 0;
for(const auto& c:cups)
{
max1=max(max1,c[1]);
max2=max(max2,c[2]);
}
if(max2>max1) return false;
return true;
}
bool findCoolest(vector<vector<dd>>& cups)
{
dd min1 = std::numeric_limits<dd>::max(), min2 = std::numeric_limits<dd>::max();
for(const auto& c:cups)
{
min1=min(min1,c[1]);
min2=min(min2,c[2]);
}
if(min2<min1) return false;
return true;
}
bool checkAvg(vector<vector<dd>>& cups)
{
dd sum1 = 0, sum2 = 0;
for(const auto& c:cups)
{
sum1 += c[1]*c[0];
sum2 += c[2]*c[0];
}
if(sum1==sum2) return true;
return false;
}
bool solution(vector<vector<dd>>& cups)
{
if(cups.empty()) return true;
if(findHottest(cups) == false) return false;
if(findCoolest(cups) == false) return false;
if(checkAvg(cups) == false) return false;
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
dd t, numOfChilds, vTea, t1, t2;
vector<vector<dd>> cups;
vector<dd> cup;
bool sol;
cin>>t;
for(ll testCase = 0; testCase<t; testCase++)
{
cin>>numOfChilds;
cups.clear();
for(ll i=0;i<numOfChilds;i++)
{
cin>>vTea>>t1>>t2;
cup = {vTea,t1,t2};
cups.emplace_back(cup);
}
sol = solution(cups);
if(sol == false) cout<<"NIE"<<'\n';
else cout<<"TAK"<<'\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 | #include <bits/stdc++.h> using ll = long long; using ull = unsigned long long; using dd = double; using namespace std; bool findHottest(vector<vector<dd>>& cups) { dd max1 = 0, max2 = 0; for(const auto& c:cups) { max1=max(max1,c[1]); max2=max(max2,c[2]); } if(max2>max1) return false; return true; } bool findCoolest(vector<vector<dd>>& cups) { dd min1 = std::numeric_limits<dd>::max(), min2 = std::numeric_limits<dd>::max(); for(const auto& c:cups) { min1=min(min1,c[1]); min2=min(min2,c[2]); } if(min2<min1) return false; return true; } bool checkAvg(vector<vector<dd>>& cups) { dd sum1 = 0, sum2 = 0; for(const auto& c:cups) { sum1 += c[1]*c[0]; sum2 += c[2]*c[0]; } if(sum1==sum2) return true; return false; } bool solution(vector<vector<dd>>& cups) { if(cups.empty()) return true; if(findHottest(cups) == false) return false; if(findCoolest(cups) == false) return false; if(checkAvg(cups) == false) return false; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); dd t, numOfChilds, vTea, t1, t2; vector<vector<dd>> cups; vector<dd> cup; bool sol; cin>>t; for(ll testCase = 0; testCase<t; testCase++) { cin>>numOfChilds; cups.clear(); for(ll i=0;i<numOfChilds;i++) { cin>>vTea>>t1>>t2; cup = {vTea,t1,t2}; cups.emplace_back(cup); } sol = solution(cups); if(sol == false) cout<<"NIE"<<'\n'; else cout<<"TAK"<<'\n'; } return 0; } |
English