这个题就是 对于两个折线,看谁能先走到 折点就按照那个时间走,
然后不断保存位置。 每个狗走的时候 都有一个方向,那么两只狗的方向向量 可以把其中一个 分成两一个向量 + 某一个向量。 这样就可以一个方向相对静止运动
另一个方向 单独运动, 这样就可以 求距离的时候 就是 点到直线了。
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define ll long long
#define maxn 100
struct Point
{
double x, y;
Point(double x = 0, double y = 0) : 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 - (Point A, Point 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)
{
if(a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
const double eps = 1e-10;
int dcmp(double x)
{
if(fabs(x) < eps) return 0; return x < 0 ? -1 : 1;
}
bool operator == (const Point &a, const Point &b)
{
return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}
double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
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 Cross(B-A, C-A); }
Vector Rotate(Vector A, double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}
double DistanceToSegment( Point p,Point a,Point b ){
if( a == b )return Length( p-a );
Point 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 abs(Cross( v1,v2 ))/Length(v1);
}
Point GetIntersection(Point P, Vector v, Point Q, Vector w)
{
Vector u = P-Q;
double t = Cross(w, u) / Cross(v, w);
return P+v*t;
}
int a,b;
Point p[maxn], q[maxn];
double Min, Max;
int kase = 0;
Point read_point()
{
Point A;
scanf("%lf%lf", &A.x, &A.y);
return A;
}
void update(Point P, Point A, Point B){
Min = min(Min, DistanceToSegment(P, A, B));
Max = max(Max, Length(P - A));
Max = max(Max, Length(P - B));
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%d%d",&a,&b);
for(int i = 0; i < a; i++)
p[i] = read_point();
for(int i = 0; i < b; i++)
q[i] = read_point();
double lena = 0;
double lenb = 0;
for(int i = 0; i < a-1; i++)
lena += Length(p[i+1] - p[i]);
for(int i = 0; i < b-1; i++)
lenb += Length(q[i+1] - q[i]);
int sa = 0, sb = 0;
Min = Length(p[0]-q[0]);
Max = Length(p[0]-q[0]);
Point pa = p[0], pb = q[0]; // 这个记录上次所处的位置
while(sa < a-1 && sb < b-1){
double la = Length(p[sa+1] - pa);
double lb = Length(q[sb+1] - pb);
double t = min(la/lena, lb/lenb); // 决定走哪个可以使某一个走到相邻的转折点处
Vector va = (p[sa+1] - pa)/la*t*lena;
Vector vb = (q[sb+1] - pb)/lb*t*lenb;
update(pa, pb, pb+vb-va);
pa = pa + va;
pb = pb + vb;
if(pa == p[sa+1]) sa++;
if(pb == q[sb+1]) sb++;
}
printf("Case %d: %.0lf\n",++kase,Max - Min);
}
return 0;
}