在本教程中,我们将讨论一个程序来查找矩形的坐标
里面有给定的分数。
为此,我们将提供一些坐标点。我们的任务是找到最小的矩形,使所有点都位于其内部,并且矩形的边应与坐标轴平行。
#include <bits/stdc++.h> using namespace std; //计算最小矩形的坐标 void print_rectangle(int X[], int Y[], int n){ //寻找最低和最高点 int Xmax = *max_element(X, X + n); int Xmin = *min_element(X, X + n); int Ymax = *max_element(Y, Y + n); int Ymin = *min_element(Y, Y + n); cout << "{" << Xmin << ", " << Ymin << "}" << endl; cout << "{" << Xmin << ", " << Ymax << "}" << endl; cout << "{" << Xmax << ", " << Ymax << "}" << endl; cout << "{" << Xmax << ", " << Ymin << "}" << endl; } int main(){ int X[] = { 4, 3, 6, 1, -1, 12 }; int Y[] = { 4, 1, 10, 3, 7, -1 }; int n = sizeof(X) / sizeof(X[0]); print_rectangle(X, Y, n); return 0; }
输出结果
{-1, -1} {-1, 10} {12, 10} {12, -1}