CodeForces - 618C —— Constellation —— 几何

来源:互联网 发布:做淘宝真的比上班累吗 编辑:程序博客网 时间:2024/05/17 20:01


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.

Example
Input
30 11 01 1
Output
1 2 3
Input
50 00 22 02 21 1
Output
1 3 5
Note

In the first sample, we can print the three indices in any order.

In the second sample, we have the following picture.

Note that the triangle formed by starts 14 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).



题意:

给你一个数n;

然后给你n组坐标(x,y)。让你挑出三个点,使得着三个点组成的三角形内没有其余的点。

任取其中一组答案即可。


思路:

先将所有坐标放入同一个结构体数组中。

然后依据y坐标相同时,按小x坐标从小到大排序;

x坐标相同时,按y坐标从小到大排序

然后前两个数组中元素连线之间肯定不会再有其它的点,所以可以从第三个开始找,找到一个点当这三个点形成的两条边不平行时,break;


判断三坐标形成的两条线段是否平行的方法,查阅了一下叫做叉积。结论记住就行了




#include <iostream>#include <cstdio>#include <cstdlib>#include <string>#include <cmath>#include <algorithm>#include <cstring>#include <map>#include <set>#include <sstream>#include <queue>#include <stack>#define INF 0x3f3f3f3f#define mem(a,b) memset(a,b,sizeof(a));#define For(a,b) for(int i = a;i<b;i++)#define ll long long#define MAX_N 100010using namespace std;struct stri{    ll x;    ll y;    int pos;}s[MAX_N];bool cmp(stri a,stri b){    if(a.x == b.x) return a.y < b.y;    else return a.x < b.x;}bool check(stri p){    if((s[0].x - p.x) * (s[1].y - p.y) != (s[0].y - p.y) * (s[1].x - p.x))        return true;    return false;}int main(){    int n;    while(~scanf("%d",&n))    {        for(int i = 0; i<n; i++)        {            ll a,b;            scanf("%lld %lld",&a,&b);            s[i].pos = i+1;            s[i].x = a;            s[i].y = b;        }        if(n == 3)        {            cout<<"1 2 3"<<endl;            continue;        }        sort(s,s + n,cmp);        for(int i = 2; i<n; i++)        {            if(check(s[i]))            {                printf("%d %d %d\n",s[0].pos,s[1].pos,s[i].pos);                break;            }        }    }    return 0;}




















0 0
原创粉丝点击