用 C++ 语言确定给定点位于内部的矩形的坐标
在本文中,我们将讨论一个程序,以便找到矩形的坐标
且给定点位于内部。
为此,我们将提供一些坐标点。我们的任务是找到最小的矩形,使所有点位于其内部,并且其边平行于坐标轴。
示例
#include <bits/stdc++.h> using namespace std; //calculating the coordinates of smallest rectangle void print_rectangle(int X[], int Y[], int n){ //finding minimum and maximum points 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}
广告