POJ 3608 Bridge Across Islands(凸包最近对踵点对)

题目链接:http://poj.org/problem?id=3608

题意:求两个多边形的最近对踵点对。(已知两个多边形不相交)

思路:模板。

View Code 
 #include 
 #include 
 #include 
 #include 
 #define min(x,y) ((x)<(y)?(x):(y))
 using namespace std;
 
 
 struct point
 {
     double x,y;
 
     point(){}
     point(double _x,double _y)
     {
         x=_x;
         y=_y;
     }
 
 
     void get()
     {
         scanf("%lf%lf",&x,&y);
     }
 };
 
 const double EPS=1e-8;
 const int MAX=10005;
 point p[MAX],q[MAX],p1[MAX],q1[MAX],temp;
 int n,m,N,M;
 
 
 int DB(double x)
 {
     if(x>EPS) return 1;
     if(x<-EPS) return -1;
     return 0;
 }
 
 
 
 double Dis(point a,point b)
 {
     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
 }
 
 //判断p在向量ab的哪一侧
 //右侧:返回正值
 //左侧:返回负值
 //在向量ab上返回0
 double cross(point a,point b,point p)
 {
     return (b.x-a.x)*(p.y-a.y)-(b.y-a.y)*(p.x-a.x);
 }
 
 
 int cmp(point a,point b)
 {
     double x=Dis(a,temp),y=Dis(b,temp);
     int flag=DB(cross(temp,a,b));
     if(flag) return flag==1;
     return DB(x-y)<=0;
 }
 
 void Graham(point p[],int n,point q[],int &m)
 {
     point t;
     int i,k=0,a,b;
     for(i=1;i1&&DB(cross(q[m-2],q[m-1],p[i]))<=0) m--;
         q[m++]=p[i];
     }
     m--;
 }
 
 
 
 
 
 double getAngle(point a1,point a2,point b1,point b2)
 {
     point t;
     t.x=b2.x-b1.x+a1.x;
     t.y=b2.y-b1.y+a1.y;
     return cross(a1,a2,t);
 }
 
 double Dis1(point a,point p,point q)
 {
     double t1=(q.x-p.x)*(a.x-p.x)+(q.y-p.y)*(a.y-p.y);
     double t2=(p.x-q.x)*(a.x-q.x)+(p.y-q.y)*(a.y-q.y);
     if(DB(t1)!=-1&&DB(t2)!=-1) return fabs(cross(a,p,q))/Dis(p,q);
     return min(Dis(a,p),Dis(a,q));
 }
 
 
 //凸包最近对踵点
 double calMinDis(point p[],int n,point q[],int m)
 {
     int sp=0,sq=0,i,a,b,tp,tq;
     double ans,flag;
     for(i=0;i

  

 

你可能感兴趣的:(POJ 3608 Bridge Across Islands(凸包最近对踵点对))