代码


struct Point
{
    Point() = default;
    double x,y;
    Point(double x,double y):x(x),y(y) {}

};
typedef Point Vector;
Vector operator + (Vector A,Vector B)
{
    return Vector(A.x + B.x,A.y + B.y);
}
Vector operator - (Vector A,Vector B)
{
    return Vector(A.x-B.x,A.y-B.y);
}
Vector operator / (Vector A,double p)
{
    return Vector(A.x/p,A.y/p);
}
Vector operator * (Vector A,double p)
{
    return Vector(A.x*p,A.y*p);
}
bool operator < (const Point &a,const Point &b)
{
    return a.x < b.x||(a.x==b.x&&a.y < b.y);
}
//const double eps = 1e-10;
int dcmp(double x)
{
    if(fabs(x)<eps)
        return 0;
    else
        return x < 0?-1:1;
}
bool operator == (const Point &a,const Point &b)
{
    return !dcmp(a.x-b.x)&&!dcmp(a.y-b.y);
}
//.....................................................
//点乘
double Dot(Vector A,Vector B)
{
    return A.x*B.x+A.y*B.y;
}
//求模
double Length(Vector A)
{
    return sqrt(A.x*A.x+A.y*A.y);
}
//求斜率
double Angle(Vector A,Vector B)
{
    return acos(Dot(A,B)/Length(A)/Length(B));
}
//叉乘
double Cross(Vector A,Vector B)
{
    return A.x*B.y - A.y*B.x;
}
//求三角形面积
double Area2(Point A,Point B,Point C)
{
    return fabs(Cross(B-A,C-A))/2;
}
//旋转一定度数,弧度制
Vector Rotate(Vector A,double rad)
{
    return Vector (A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
//单位法线
Vector Normal(Vector A)
{
    double L = Length(A);
    return Vector(-A.y/L,A.x/L);
}
//调用前确保直线有唯一交点,当且仅当Cross(v,w)非0
//求直线的交点
Point Get_Line_Intersection(Point P,Vector v,Point Q,Vector w)
{
    Vector u = P - Q;
    double t = Cross(w,u)/Cross(v,w);
    return P+v*t;
}
//点到直线的距离
double Distance_To_Line(Point P,Point A,Point B)
{
    Vector v1 = B-A,v2 = P-A;
    return fabs(Cross(v1,v2)/Length(v1));
}
//点到线段的距离
double Distance_To_Segment(Point P,Point A,Point B)
{
    if(A==B) return Length(P-A);
    Vector v1 = B-A,v2 = P-A,v3 = P-B;
    if(dcmp(Dot(v1,v2))<0) return Length(v2);
    else if(dcmp(Dot(v1,v3))>0) return Length(v3);
    else return fabs(Cross(v1,v2))/Length(v1);
}
//求投影点
Point Get_Line_Projection(Point P,Point A,Point B)
{
    Vector v = B- A;
    return A + v*(Dot(v,P-A)/Dot(v,v));
}
//线段相交判定 相交不在线段的端点
bool Segment_Proper_Intersection(Point a1,Point a2,Point b1,Point b2)
{
    double c1 =  Cross(a2-a1,b1-a1),c2 = Cross(a2-a1,b2-a1),
           c3 =  Cross(b2-b1,a2-b1),c4 = Cross(b2-b1,a1-b1);
    return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0;
}
//判断点是否在线段上(不包括端点)
bool Onsegment(Point p,Point a1,Point a2)
{
    return dcmp(Cross(a1-p,a2-p))==0&&dcmp(Dot(a1-p,a2-p))<0;
}
bool Intersect_Onsegment(Point a,Point b,Point c,Point d)
{
    return Onsegment(a,c,d)||Onsegment(b,c,d)||Onsegment(c,a,b)||Onsegment(d,a,b);
}
Point a[100];
Point b[100];
double Min = inf,Max = -inf;
void Update(Point A,Point B,Point C)
{
    Min = min(Min,Distance_To_Segment(A,B,C));
    Max = max(Max,Length(B-A));
    Max = max(Max,Length(C-A));
}
int main(void)
{

    int T;
    cin>>T;
    int kase = 0;
    int A,B;
    while(T--)
    {
       scanf("%d %d",&A,&B);
       for(int i = 0;i < A; ++i)
            scanf("%lf %lf",&a[i].x,&a[i].y);
       for(int i = 0;i < B; ++i)
            scanf("%lf %lf",&b[i].x,&b[i].y);
       double LenA = 0,LenB = 0;
       for(int i = 0;i < A-1; ++i)
        LenA += Length(a[i+1]-a[i]);
       for(int i = 0;i < B-1; ++i)
        LenB += Length(b[i+1]-b[i]);

       int Sa = 0,Sb = 0;
       Point Pa,Pb;
       Pa = a[0];
       Pb = b[0];
       Min = inf,Max = -inf;
       while(Sa<A-1&&Sb<B-1)
       {
          double da = Length(a[Sa+1]-Pa);
          double db = Length(b[Sb+1]-Pb);
          double T = min(da/LenA,db/LenB);
          Vector va = (a[Sa+1]-Pa)/da*T*LenA;
          Vector vb = (b[Sb+1]-Pb)/db*T*LenB;

          Update(Pa,Pb,Pb+vb-va);
          Pa = Pa + va;
          Pb = Pb + vb;
          if(a[Sa+1]==Pa) Sa++;
          if(b[Sb+1]==Pb) Sb++;
       }
        printf("Case %d: %.f\n",++kase,round(Max-Min));
    }

    return 0;
}