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

来源:互联网 发布:怎么设置淘宝店logo 编辑:程序博客网 时间:2024/05/20 16:35


C. Constellation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
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个点,求三个点使得他们围成三角形。而且这个三角形内部没有点。


题解:按照字典序排序,先选取2个点,然后枚举第三个点是否与前2点共线,我是使用斜率去判断是否在一条线上,这里注意一下不要直接求出斜率K,还是移项一下,使用乘积的形式,不然会出现除以0的情况出错




#include <set>#include <map>#include <list> #include <cmath> #include <queue> #include <vector>#include <cstdio> #include <string> #include <cstring>#include <iomanip> #include <iostream> #include <sstream>#include <algorithm>#define  LL long long #define inf 0x3f3f3f3fusing namespace std;#define N 100005struct point {    LL x,y;   int org;};point convex[N];bool cmp(const point &x1,const point &x2){if(x2.x!=x1.x)return x1.x<x2.x;return x1.y<x2.y;}bool judge(point &x1,point &x2,point &x3){return ((x2.y-x3.y)*(x1.x-x2.x))!=((x1.y-x2.y)*(x2.x-x3.x));}int main(){#ifdef CDZSCfreopen("i.txt","r",stdin);#endifint n;while(~scanf("%d",&n)){for(int i=0;i<n;i++){scanf("%lld%lld",&convex[i].x,&convex[i].y);convex[i].org=i+1;}sort(convex,convex+n,cmp);printf("%d %d ",convex[0].org,convex[1].org);for(int i=2;i<n;i++){if(judge(convex[0],convex[1],convex[i])){printf("%d\n",convex[i].org);break;}}}return 0;}


0 0
原创粉丝点击