给你俩凸包,问你它们的最短距离。
咋做就不讲了,经典题,网上一片题解。
把凸包上的点逆时针排序。可以取它们的平均点,然后作极角排序。
旋转卡壳其实是个很模板化的东西……
先初始化分别在凸包P和Q上取哪个点,一般在P上取纵坐标最小的点,在Q上取纵坐标最大的点
for i=1 to n(n是凸包P上的点数)
{
while(两条边的叉积>0)
{
凸包Q上的点++
}
计算当前两条边之间的答案(或者说每条边的2个端点到另一条边的答案)
凸包P上的点++
}
#include#include #include using namespace std;#define EPS 0.0000000001struct Point{ double x,y; Point(){} Point(const double &X,const double &Y) { x=X; y=Y; } double Length() { return sqrt(x*x+y*y); }}p[2][10010],bao[2][10010],ave;typedef Point Vector;Vector operator - (const Point &a,const Point &b){ return Vector(a.x-b.x,a.y-b.y);}bool cmp (const Point &a,const Point &b){ return atan2((a-ave).y,(a-ave).x) (-EPS)) return v3.Length(); else return fabs(Cross(v1,v2))/v1.Length();}int n,m;int main(){ //freopen("y.in","r",stdin); while(1) { scanf("%d%d",&n,&m); if(n==0 && m==0) break; for(int i=0;i EPS) nowQ=i; double ans=1000000000000000007.0; for(int i=0;i EPS) nowQ=(nowQ+1)%m; ans=min(ans, min(calc(p[0][nowP],p[1][nowQ],p[1][(nowQ+1)%m]), min(calc(p[0][(nowP+1)%n],p[1][nowQ],p[1][(nowQ+1)%m]), min(calc(p[1][nowQ],p[0][nowP],p[0][(nowP+1)%n]), calc(p[1][(nowQ+1)%m],p[0][nowP],p[0][(nowP+1)%n]))))); nowP=(nowP+1)%n; } printf("%.5lf\n",ans); } return 0;}