题意:给你n个点(n<=1e5),保证所有点不在同一直线上,让你找三个点,形成一个三角形,且该三角形内没有点。
思路:先按x轴排序,x相同按y排序。因为保证所有点不在同一直线上,这样前两个必定可以和后面某个点构成三角形,且从第三个开始找第一个能形成三角形的内部一定没有其他点,因为如果有其他点,那这个内部点同样可以与前两个点形成三角形,且在这个点前面。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
struct node
{
ll x, y;
int id;
bool operator < (const node &a) const
{
if(x == a.x) return y < a.y;
return x < a.x;
}
}a[maxn];
bool judge(node aa, node bb, node cc)
{
return (cc.y-bb.y)*(bb.x-aa.x)!=(bb.y-aa.y)*(cc.x-bb.x);
}
int main(void)
{
int n;
while(cin >> n)
{
for(int i = 1; i <= n; i++)
scanf("%d%d", &a[i].x, &a[i].y), a[i].id = i;
sort(a+1, a+1+n);
for(int i = 3; i <= n; i++)
if(judge(a[1], a[2], a[i]))
{
printf("%d %d %d\n", a[1].id, a[2].id, a[i].id);
break;
}
}
return 0;
}