传送门:http://codeforces.com/problemset/problem/618/C
已知若干的点的坐标,并且没有两个点坐标相同,所有点不会均在一条线上,求三个顶点构成的任意一个三角形,是其余的点都严格在三角形外。
水题。。。结果因为数据范围WA了
A1:按极角排序,所以第一个点,第二个点,和之后第一个不共线的点就是答案,因为数据范围,所以算叉乘的时候要用long long
A2:按坐标排序,先排x再排y,选点同上
代码如下:
#include<cstdio>
#include<algorithm>
using namespace std;
struct star
{
long long x,y;
int no;
};
star s[100005];
int now;
int n;
long long angle(star a,star b,star c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
long long dist(star a,star b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
bool cmp(const star a,const star b)
{
long long t=angle(s[1],a,b);
if (t>0)
{
return 1;
}
if (t<0)
{
return 0;
}
return dist(s[1],a)<dist(s[1],b);
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%I64d%I64d",&s[i].x,&s[i].y);
s[i].no=i;
}
now=1;
for (int i=2;i<=n;i++)
{
if (s[i].x<s[now].x || ((s[i].x==s[now].x) && (s[i].y<s[now].y)))
{
now=i;
}
}
s[n+1]=s[1];
s[1]=s[now];
s[now]=s[n+1];
sort(s+2,s+n+1,cmp);
for (int i=3;i<=n;i++)
{
if (angle(s[1],s[2],s[i])!=0)
{
printf("%d %d %d\n",s[1].no,s[2].no,s[i].no);
break;
}
}
return 0;
}