Codeforces--618C--Constellation(数学几何)(技巧)

来源:互联网 发布:java学会了能做什么 编辑:程序博客网 时间:2024/05/17 06:13
Constellation
Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

Submit Status

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
30 11 01 1
Output
1 2 3
Input
50 00 22 02 21 1
Output
1 3 5

Hint

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).

Source

Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)

题意:给出n个点的坐标,然后找一个三角形,这个三角形中不含其他的点,输出可能有多种情况,输出一种就好

思路:将所有的点排序,按照x升序排列,x相同的按照y升序,然后取最靠边的两个点,作为三角形的其中两个点,然后取这两个点后面的点,判断是否可以构成三角形,因为已经排过序,所以我们使用第一个点的时候不会出现三角形中间夹一个点的情况,即使后边会出现舍点的情况,但这也是因为这个点跟前边的两个点共线,形成三角形是不允许三点共线的,因此排序之后就是枚举,点的坐标范围有点大,所以__int64最好,要不然就会wa到12组,不要问我为什么                             

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{__int64 x,y;int num;}p[100000+10];bool cmp(node s1,node s2){if(s1.x==s2.x)return s1.y<s2.y;return s1.x<s2.x;}bool judge(node s){if((p[1].x-s.x)*(p[2].y-s.y)==(p[1].y-s.y)*(p[2].x-s.x))return false;return true;}int main(){int n;while(scanf("%d",&n)!=EOF){for(int i=1;i<=n;i++){scanf("%I64d%I64d",&p[i].x,&p[i].y);p[i].num=i;}sort(p+1,p+1+n,cmp);if(n==3)printf("1 2 3\n");else{for(int i=3;i<=n;i++){if(judge(p[i])){printf("%d %d %d\n",p[1].num,p[2].num,p[i].num);break;}}}}return 0;}

0 0
原创粉丝点击