#include <iostream> #include <vector> using namespace std; struct Offer { int Wl, Wr, Hd, Hu; bool operator==(const Offer& other) const; friend istream& operator>>(istream& str, Offer& o); }; bool Offer::operator==(const Offer& other) const { return Wl == other.Wl && Wr == other.Wr && Hd == other.Hd && Hu == other.Hu; } istream& operator>>(istream& str, Offer& o) { str >> o.Wl >> o.Wr >> o.Hd >> o.Hu; return str; } Offer getBounds(const vector<Offer>& offers) { Offer o = { offers[0].Wl, offers[0].Wr, offers[0].Hd, offers[0].Hu }; for (unsigned int i = 1; i < offers.size(); ++i) { o.Wl = min(o.Wl, offers[i].Wl); o.Wr = max(o.Wr, offers[i].Wr); o.Hd = min(o.Hd, offers[i].Hd); o.Hu = max(o.Hu, offers[i].Hu); } return o; } bool contains(const vector<Offer>& offers, const Offer& o) { for (unsigned int i = 0; i < offers.size(); ++i) { if (offers[i] == o) return true; } return false; } void doTest() { int n; cin >> n; vector<Offer> offers; for (int i = 0; i < n; ++i) { Offer o; cin >> o; offers.push_back(o); } Offer max = getBounds(offers); if (contains(offers, max)) cout << "TAK" << endl; else cout << "NIE" << endl; } int main() { ios_base::sync_with_stdio(0); int t; cin >> t; for (int i = 0; i < t; ++i) { doTest(); } 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 | #include <iostream> #include <vector> using namespace std; struct Offer { int Wl, Wr, Hd, Hu; bool operator==(const Offer& other) const; friend istream& operator>>(istream& str, Offer& o); }; bool Offer::operator==(const Offer& other) const { return Wl == other.Wl && Wr == other.Wr && Hd == other.Hd && Hu == other.Hu; } istream& operator>>(istream& str, Offer& o) { str >> o.Wl >> o.Wr >> o.Hd >> o.Hu; return str; } Offer getBounds(const vector<Offer>& offers) { Offer o = { offers[0].Wl, offers[0].Wr, offers[0].Hd, offers[0].Hu }; for (unsigned int i = 1; i < offers.size(); ++i) { o.Wl = min(o.Wl, offers[i].Wl); o.Wr = max(o.Wr, offers[i].Wr); o.Hd = min(o.Hd, offers[i].Hd); o.Hu = max(o.Hu, offers[i].Hu); } return o; } bool contains(const vector<Offer>& offers, const Offer& o) { for (unsigned int i = 0; i < offers.size(); ++i) { if (offers[i] == o) return true; } return false; } void doTest() { int n; cin >> n; vector<Offer> offers; for (int i = 0; i < n; ++i) { Offer o; cin >> o; offers.push_back(o); } Offer max = getBounds(offers); if (contains(offers, max)) cout << "TAK" << endl; else cout << "NIE" << endl; } int main() { ios_base::sync_with_stdio(0); int t; cin >> t; for (int i = 0; i < t; ++i) { doTest(); } return 0; } |