给定平面上N个点P1=(X1, Y1), P2=(X2, Y2), ... PN=(XN, YN)。
请你从中找到两个不同的点Pi和Pj满足:其他所有点都在Pi和Pj连线的同一侧(可以在连线上)。
如果有多组答案满足条件,你可以输出任意一组。
Input
Sample Input
第一行包含一个整数N。
以下N行每行包含两个整数Xi和Yi。
对于50%的数据,1 ≤ N ≤ 1000
对于100%的数据,1 ≤ N ≤ 100000 0 ≤ Xi, Yi ≤ 1000000
Output输出由一个空格隔开的两个整数i和j,注意1 ≤ i, j ≤ N且i ≠ j。
6 0 10 7 0 8 8 10 18 15 13 20 4Sample Output
5 6先找到横坐标最小的点,以他为起点,找到与它链接斜率最大的点。。。
#include<stdio.h>
#include<math.h>
struct node
{
int x;
int y;
};
struct node a[100005];
int main()
{
int n;
scanf("%d",&n);
struct node t;
int tnum;
t.x=9999;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
if(a[i].x<t.x)
{
t=a[i];
tnum=i;
}
}
double ans=-100;
int tans=0;
for(int i=0;i<n;i++)
{
if(tnum!=i)
{
if(a[i].x-t.x==0)
{
tans=i;
break;
}
else
{
double tt=(a[i].y-t.y)/double(a[i].x-t.x);
{
if(tt>tans)
{
ans=tt;
tans=i;
}
}
}
}
}
printf("%d %d",tnum+1,tans+1);
return 0;
}