【CodeForces 618C】Constellation(几何水题)

来源:互联网 发布:Mac的tomcat打不开8080 编辑:程序博客网 时间:2024/05/02 20:48

Description

Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.

In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.

It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.

Input

The first line of the input contains a single integer n (3 ≤ n ≤ 100 000).

Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109).

It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.

Output

Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem.

If there are multiple possible answers, you may print any of them.

Sample Input

Input

3
0 1
1 0
1 1

Output

1 2 3

Input

5
0 0
0 2
2 0
2 2
1 1

Output

1 3 5

题目大意

给你n个点的坐标,要你选3个点构成三角形并且是除这三个点外的所有点都落在这个三角形之外,输出所选择的三个点的序号。

思路

将每个点按x坐标从小到大排列,x坐标相同的情况在根据y坐标从小到大排列(这样可以保证选出来的三个点所构成的三角形尽量小,并且其他点必定在它之外),直接选择第一个和第二个作为前两个序号,接下来枚举剩下的n-2个点判断否满足条件。

代码

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define ll long longusing namespace std;const int maxn=1e5+5;struct proc{    ll list;    ll x;    ll y;}map[maxn];int n;int cmp(proc a,proc b){    return (a.x<b.x)||(a.x==b.x&&a.y<b.y);}int main(){    while(~scanf("%lld",&n))    {        for(int i=1;i<=n;i++)        {            scanf("%lld %lld",&map[i].x,&map[i].y);            map[i].list=i;        }        sort(map+1,map+1+n,cmp);        int m=3;        while((map[1].x-map[2].x)*(map[1].y-map[m].y)==(map[1].y-map[2].y)*(map[1].x-map[m].x))         {            m++;        }        printf("%lld %lld %lld\n",map[1].list,map[2].list,map[m].list);    }    return 0;}
0 0
原创粉丝点击