http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100
首先按x坐标排序,然后相邻的三个点A,B,C 组成的三条直线必然有K(AC)<max(K(A,B),K(B,C));(K是斜率)
所以斜率一定会在相邻的两点中产生,排序O(nlogn),更新最大值O(n)。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1010
#define maxv 3000
#define mod 1000000000
using namespace std; struct point
{
int x,y,id;
bool operator < (const point a) const
{
return x<a.x;
}
}p[];
int main()
{
// freopen("a.txt","r",stdin);
int n,j,k;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].id=i;
}
sort(p+,p+n+);
double ans=;
for(int i=;i<=n;i++)
{
if(p[i].y==p[i-].y) continue;
if((p[i].y-p[i-].y)*1.0/(p[i].x-p[i-].x)>ans)
{
ans=(p[i].y-p[i-].y)*1.0/(p[i].x-p[i-].x);
j=p[i].id;
k=p[i-].id;
}
}
printf("%d %d\n",k,j);
return ;
}