【凸包 两凸包最近点对距离】POJ - 3608 L - Bridge Across Islands

L - Bridge Across Islands POJ - 3608

Thousands of thousands years ago there was a small kingdom located in the middle of the Pacific Ocean. The territory of the kingdom consists two separated islands. Due to the impact of the ocean current, the shapes of both the islands became convex polygons. The king of the kingdom wanted to establish a bridge to connect the two islands. To minimize the cost, the king asked you, the bishop, to find the minimal distance between the boundaries of the two islands.

Input

The input consists of several test cases.
Each test case begins with two integers NM. (3 ≤ NM ≤ 10000)
Each of the next N lines contains a pair of coordinates, which describes the position of a vertex in one convex polygon.
Each of the next M lines contains a pair of coordinates, which describes the position of a vertex in the other convex polygon.
A line with N = M = 0 indicates the end of input.
The coordinates are within the range [-10000, 10000].

Output

For each test case output the minimal distance. An error within 0.001 is acceptable.

Sample Input

4 4
0.00000 0.00000
0.00000 1.00000
1.00000 1.00000
1.00000 0.00000
2.00000 0.00000
2.00000 1.00000
3.00000 1.00000
3.00000 0.00000
0 0

Sample Output

1.00000
#include 
#include 
#include 
#include 
#include 
#include 
#define inf 0x3f3f3f3f
#define eps 1e-9
using namespace std;
struct Point
{
    double x,y;
} a[10005],b[10005];
int n,m;
double Cross(Point a,Point b,Point c)
{
    return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
void anticlockwise(Point a[],int n)
{
    for (int i=0; ieps) return;
        else if (tmp<-eps)
        {
            reverse(a,a+n);
            return;
        }
    }
}
double dis(Point a,Point b)
{
    return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
double mult(Point a,Point b,Point c)
{
    return (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y);
}
double Getdis(Point a,Point b,Point c)
{
    if (dis(a,b)eps)
            ymaxb=(ymaxb+1)%m;
        if (tmp<-eps) ans=min(ans,Getdis(a[ymina],a[ymina+1],b[ymaxb]));
        else ans=min(ans,mindis(a[ymina],a[ymina+1],b[ymaxb],b[ymaxb+1]));
        ymina=(ymina+1)%n;
    }
    return ans;
}
int main()
{
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        if (!n&&!m) break;
        for (int i=0; i

 

你可能感兴趣的:(凸包,模板)