题意:在一个平面直角坐标系当中给你n个点,然后选择其中的三个点要求这个三角形里面没有其他的点。
思路:如果要三角形没有其他的的点,其实只要将所有的点排一个序然后再找这个三角形,按照x从小到大排序,如果x相同的话,按照y坐标从小到大,然后判断这三个点不共线就可以找到这个三角形了。
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define MAXN 100010
#define INF 10000000
#define MOD 1000000007
#define LL long long
using namespace std;
struct Node {
LL x;
LL y;
int id;
} point[MAXN];
bool cmp(const Node &x1, const Node &x2) {
if (x1.x == x2.x)
return x1.y < x2.y;
return x1.x < x2.x;
}
int main() {
std::ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> point[i].x >> point[i].y;
point[i].id = i + 1;
}
sort(point, point + n, cmp);
for (int i = 2; i < n; ++i) {
if ((point[i].x - point[0].x) * (point[i].y - point[1].y) !=
(point[i].x - point[1].x) * (point[i].y - point[0].y)) {
cout << point[0].id << " " << point[1].id << " " << point[i].id << endl;
break;
}
}
return 0;
}