题意是求一堆点中的两个点,其连接的直线线要能等分所有点。
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int MAX = 10010;
const double eps = 1e-6;
struct point{ double x,y;int ind;};
point p[MAX];
double crossProduct(point a,point b,point c)//向量 ac 在 ab 的方向
{
return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y);
}
bool cmp(point a,point b)
{
return crossProduct(p[0],a,b) < eps;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].ind = i+1;
}
int t = 0;
for(int i=1; i<n; i++)
if( p[i].x < p[t].x || (p[i].x == p[t].x && p[i].y < p[t].y) )
t = i;
swap(p[t],p[0]);
sort(p+1,p+n,cmp);
printf("%d %d\n",p[0].ind,p[n/2].ind);
return 0;
}