思路:我们找到最左边(或上,下,右)的点,然后找一条斜率最大或者最小的点就是答案。
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int n;
struct Node
{
double x, y, id;
}a[MAXN];
bool cmp1(Node A, Node B)
{
return A.x < B.x;
}
bool cmp2(Node A, Node B)
{
return abs(A.y - a[0].y) / abs(A.x - a[0].x) > abs(B.y - a[0].y) / abs(B.x - a[0].x);
}
int main()
{
ios::sync_with_stdio(false);
while (~scanf("%d", &n))
{
for (int i = 0; i < n; i++)
{
scanf("%lf%lf", &a[i].x, &a[i].y);
a[i].id = i + 1;
}
sort(a, a + n, cmp1);//找到最左边的点
sort(a + 1, a + n, cmp2);//找到和最左边点斜率最大的那个点
cout << a[0].id << " " << a[1].id << endl;
}
return 0;
}
/*
6
0 10
7 0
8 8
10 18
15 13
20 4
*/