#include <iostream> #include <cstdlib> using namespace std; int getResult(void); void getData(int** data, int n); int calculateData(int** data, int n); int main(int argc, char** argv) { int t; cin >> t; int* results = (int*)malloc(t * sizeof(int)); for (int i = 0; i < t; ++i){ results[i] = getResult(); } for (int i = 0; i < t; ++i){ if (results[i]) cout << "TAK\n"; else cout << "NIE\n"; } return 0; } int getResult(void) { int n; cin >> n; int** data = (int**)malloc(n * sizeof(int*)); for (int i = 0; i < n; ++i){ data[i] = (int*)malloc(4 * sizeof(int)); } getData(data, n); int mIndex = 0; int temp = calculateData(data, n); free(data); return temp; } void getData(int** data, int n) { for (int i = 0; i < n; ++i){ for (int j = 0; j < 4; ++j){ cin >> data[i][j]; } } } int calculateData(int** data, int n) { bool answerExists = true; int toCheckIndex = 0; for (int i = 1; i < n; ++i){ bool widthCheck = ((data[toCheckIndex][0] <= data[i][0] && data[toCheckIndex][1] >= data[i][1]) || (data[toCheckIndex][0] < data[i][0] && data[toCheckIndex][1] >= data[i][1])); bool heightCheck = ((data[toCheckIndex][2] <= data[i][2] && data[toCheckIndex][3] >= data[i][3]) || (data[toCheckIndex][2] < data[i][2] && data[toCheckIndex][3] >= data[i][3])); bool invWidthCheck = ((data[toCheckIndex][0] >= data[i][0] && data[toCheckIndex][1] <= data[i][1]) || (data[toCheckIndex][0] > data[i][0] && data[toCheckIndex][1] <= data[i][1])); bool invHeightCheck = ((data[toCheckIndex][2] >= data[i][2] && data[toCheckIndex][3] <= data[i][3]) || (data[toCheckIndex][2] > data[i][2] && data[toCheckIndex][3] <= data[i][3])); if (widthCheck && heightCheck && answerExists){ }else if (invWidthCheck && invHeightCheck){ toCheckIndex = i; answerExists = true; }else { answerExists = false; } } if (answerExists){ return 1; } else{ 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 | #include <iostream> #include <cstdlib> using namespace std; int getResult(void); void getData(int** data, int n); int calculateData(int** data, int n); int main(int argc, char** argv) { int t; cin >> t; int* results = (int*)malloc(t * sizeof(int)); for (int i = 0; i < t; ++i){ results[i] = getResult(); } for (int i = 0; i < t; ++i){ if (results[i]) cout << "TAK\n"; else cout << "NIE\n"; } return 0; } int getResult(void) { int n; cin >> n; int** data = (int**)malloc(n * sizeof(int*)); for (int i = 0; i < n; ++i){ data[i] = (int*)malloc(4 * sizeof(int)); } getData(data, n); int mIndex = 0; int temp = calculateData(data, n); free(data); return temp; } void getData(int** data, int n) { for (int i = 0; i < n; ++i){ for (int j = 0; j < 4; ++j){ cin >> data[i][j]; } } } int calculateData(int** data, int n) { bool answerExists = true; int toCheckIndex = 0; for (int i = 1; i < n; ++i){ bool widthCheck = ((data[toCheckIndex][0] <= data[i][0] && data[toCheckIndex][1] >= data[i][1]) || (data[toCheckIndex][0] < data[i][0] && data[toCheckIndex][1] >= data[i][1])); bool heightCheck = ((data[toCheckIndex][2] <= data[i][2] && data[toCheckIndex][3] >= data[i][3]) || (data[toCheckIndex][2] < data[i][2] && data[toCheckIndex][3] >= data[i][3])); bool invWidthCheck = ((data[toCheckIndex][0] >= data[i][0] && data[toCheckIndex][1] <= data[i][1]) || (data[toCheckIndex][0] > data[i][0] && data[toCheckIndex][1] <= data[i][1])); bool invHeightCheck = ((data[toCheckIndex][2] >= data[i][2] && data[toCheckIndex][3] <= data[i][3]) || (data[toCheckIndex][2] > data[i][2] && data[toCheckIndex][3] <= data[i][3])); if (widthCheck && heightCheck && answerExists){ }else if (invWidthCheck && invHeightCheck){ toCheckIndex = i; answerExists = true; }else { answerExists = false; } } if (answerExists){ return 1; } else{ return 0; } } |