解题思路:
1、求n个点的凸包,因为那两个点一定在凸包上;
2、暴力求解,如果题目时间卡的紧的话,会超时;所以我们用旋转卡壳法;
代码如下:
#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<time.h>
#include<math.h>
#define N 1005
#define eps 1e-9
#define pi acos(-1.0)
#define P system("pause")
using namespace std;
struct node
{
int id;
double x,y;
}p[N],ch[N];
int xx,yy;
node operator - (node a,node b)
{
a.x -= b.x;
a.y -= b.y;
return a;
}
double cross(node a, node b)
{
return a.x*b.y - a.y*b.x;
}
bool cmp(node a,node b)
{
if(a.x != b.x)
return a.x < b.x;
if(a.y != b.y)
return a.y < b.y;
return a.id < b.id;
}
double dist(node a,node b)
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
int convexhull(int n)
{
sort(p,p+n,cmp);
int i,m = 0;
int c = 1;
for(i = 1; i < n; i++)
{
if(p[i].x != p[i-1].x || p[i].y != p[i-1].y)
p[c++] = p[i];
}
n = c;
for(i=0; i<n; i++)
{
while(m>1 && cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0)
m--;
ch[m++] = p[i];
}
int k = m;
for(i = n-2; i >=0; i--)
{
while(m > k && cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) <= 0)
m--;
ch[m++] = p[i];
}
if(n > 1) m--;
return m;
}
double rotating_calipers(int m)
{
xx = ch[0].id;
yy = ch[1].id;
int q = 1;
double ans = 0;
ch[m] = ch[0];
int i;
for(i = 0; i < m; i++)
{
while(cross(ch[i+1]-ch[i],ch[q+1]-ch[i]) > cross(ch[i+1]-ch[i],ch[q]-ch[i]) )
q = (q+1)%m;
if(dist(ch[i],ch[q]) > ans)
{
xx = ch[i].id; yy = ch[q].id;
ans = dist(ch[i],ch[q]);
}
if(dist(ch[i+1],ch[q+1]) > ans)
{
xx = ch[i+1].id; yy = ch[q+1].id;
ans = dist(ch[i+1],ch[q+1]);
}
}
return ans;
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int n,z=1;
while(scanf("%d",&n) && n)
{
int i;
for(i = 0; i < n; i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].id = i;
}
int top = convexhull(n);
// for(i = 0; i < top; i++)
// cout<<ch[i].x<<" "<<ch[i].y<<" "<<ch[i].id<<endl;
rotating_calipers(top);
if(yy < xx)
{
i = yy; yy = xx; xx = i;
}
printf("Case %d: %d %d\n",z++,xx,yy);
}
// P;
return 0;
}