There are nnn points P1P2…PnP_1P_2dotsP_nP1P2…Pn in a plane forming a convex polygon The coordinates of the iii-th point PiP_iPi are xiyix_iy_ixiyi You need to find three pairwise distinct indic
To solve this problem, we can iterate through all possible combinations of three points (r, s, t) and check if the triangle formed by these points is the anticomplementary triangle of any other triangle formed by three points.
Here's the C++ code to solve the problem:
#include <iostream>
#include <vector>
using namespace std;
struct Point {
int x, y;
};
bool isAnticomplementary(const Point& p, const Point& q, const Point& r) {
int ax = q.x - p.x;
int ay = q.y - p.y;
int bx = r.x - p.x;
int by = r.y - p.y;
int cx = -ax - bx;
int cy = -ay - by;
return (cx * cx + cy * cy == ax * ax + ay * ay);
}
int main() {
int n;
cin >> n;
vector<Point> points(n);
for (int i = 0; i < n; i++) {
cin >> points[i].x >> points[i].y;
}
for (int r = 0; r < n; r++) {
for (int s = 0; s < n; s++) {
for (int t = 0; t < n; t++) {
if (r != s && r != t && s != t &&
isAnticomplementary(points[r], points[s], points[t])) {
cout << r + 1 << " " << s + 1 << " " << t + 1 << endl;
return 0;
}
}
}
}
return 0;
}
The code first reads the number of points (n) and their coordinates into a vector of Point structures. Then, it iterates through all possible combinations of three points and checks if the triangle formed by these points is the anticomplementary triangle of any other triangle formed by three points. If a matching triangle is found, the program prints the indices of the selected points and exits
原文地址: https://www.cveoy.top/t/topic/h7PH 著作权归作者所有。请勿转载和采集!