#include <iostream> using namespace std; struct offert { int wmin; int wmax; int hmin; int hmax; int len; void set(int wmin, int wmax, int hmin, int hmax) { this->wmin = wmin; this->wmax = wmax; this->hmin = hmin; this->hmax = hmax; len = ((wmax * hmax) - (wmin * hmin)); } bool contain(offert& instance) { if(wmin > instance.wmin) return false; if(wmax < instance.wmax) return false; if(hmin > instance.hmin) return false; if(hmax < instance.hmax) return false; return true; } }; int searchMaxLen(offert* offerts, int n) { int maxLen = 0; int maxPos = 0; for(int i = 0; i < n; i++) { if(offerts[i].len > maxLen) { maxLen = offerts[i].len; maxPos = i; } } return maxPos; } int main() { int t = 0; int n = 0; int wmin=0, wmax=0, hmin=0, hmax=0; int maxPos = 0; offert* offerts = NULL; bool majorize = true; cin.sync_with_stdio(false); cin >> t; for(int i = 0; i < t; i++) { cin >> n; offerts = new offert[n]; majorize = true; for(int j = 0; j < n; j++) { cin >> wmin >> wmax >> hmin >> hmax; offerts[j].set(wmin, wmax, hmin, hmax); } maxPos = searchMaxLen(offerts, n); for(int j = 0; j < n; j++) { if(j == maxPos) { continue; } if(!offerts[maxPos].contain(offerts[j])) { majorize = false; break; } } if(majorize) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } delete [] offerts; } 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 105 106 | #include <iostream> using namespace std; struct offert { int wmin; int wmax; int hmin; int hmax; int len; void set(int wmin, int wmax, int hmin, int hmax) { this->wmin = wmin; this->wmax = wmax; this->hmin = hmin; this->hmax = hmax; len = ((wmax * hmax) - (wmin * hmin)); } bool contain(offert& instance) { if(wmin > instance.wmin) return false; if(wmax < instance.wmax) return false; if(hmin > instance.hmin) return false; if(hmax < instance.hmax) return false; return true; } }; int searchMaxLen(offert* offerts, int n) { int maxLen = 0; int maxPos = 0; for(int i = 0; i < n; i++) { if(offerts[i].len > maxLen) { maxLen = offerts[i].len; maxPos = i; } } return maxPos; } int main() { int t = 0; int n = 0; int wmin=0, wmax=0, hmin=0, hmax=0; int maxPos = 0; offert* offerts = NULL; bool majorize = true; cin.sync_with_stdio(false); cin >> t; for(int i = 0; i < t; i++) { cin >> n; offerts = new offert[n]; majorize = true; for(int j = 0; j < n; j++) { cin >> wmin >> wmax >> hmin >> hmax; offerts[j].set(wmin, wmax, hmin, hmax); } maxPos = searchMaxLen(offerts, n); for(int j = 0; j < n; j++) { if(j == maxPos) { continue; } if(!offerts[maxPos].contain(offerts[j])) { majorize = false; break; } } if(majorize) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } delete [] offerts; } return 0; } |