题目链接:http://codeforces.com/problemset/problem/618/C
题意:给出n个点,要求以这些点构造一个三角形,三角形的边不能有其他点,三角形内也不可以有其他点
思路:用点的x坐标或者y坐标排序,以第一个和第二个点为三角形2个点,寻找第三个点,排序过后就排除了有其他点还在边上的情况了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL long long
using namespace std;
struct Node
{
LL x,y,pos;
}s[100030];
bool cmp(Node p,Node q)
{
if (p.x!=q.x)return p.x<q.x;
else return p.y<q.y;
}
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
for (int i=0;i<n;i++)
{
scanf("%I64d%I64d",&s[i].x,&s[i].y);
s[i].pos=i+1;
}
sort(s,s+n,cmp);
for (int i=2;i<n;i++)
{
LL x1=s[0].x,y1=s[0].y;
LL x2=s[1].x,y2=s[1].y;
LL x3=s[i].x,y3=s[i].y;
LL k1=(x1-x2)*(y1-y3);
LL k2=(x1-x3)*(y1-y2);
if ((k1!=k2))
{
printf("%I64d %I64d %I64d\n",s[0].pos,s[1].pos,s[i].pos);
break;
}
}
}
}