LEM - RIVER
Tác giả: RR
Ngôn ngữ: Pascal
{$R+,Q+,N+}
uses math;
const
FINP='';
FOUT='';
MAXN=1001;
oo=1000000001;
var
f1,f2:text;
x1,y1,x2,y2:array[1..MAXN] of double;
m,n:longint;
kq:double;
procedure openF;
begin
assign(f1,FINP); reset(f1);
assign(f2,FOUT); rewrite(f2);
end;
procedure closeF;
begin
close(f1); close(f2);
end;
procedure inp;
begin
read(f1,n,m);
for n:=1 to n do read(f1,x1[n],y1[n]);
for m:=1 to m do read(f1,x2[m],y2[m]);
end;
procedure ans;
begin
writeln(f2,kq:0:3);
end;
function kc(x1,y1,x2,y2:double):double;
begin
kc:=sqrt(sqr(x1-x2)+sqr(y1-y2));
end;
function dist(x,y,x1,y1,x2,y2:double):double;
var
a,b,t,xh,yh:double;
begin
a:=x2-x1;
b:=y2-y1;
t:=(a*(x-x1)+b*(y-y1))/(a*a+b*b);
xh:=x1+a*t; yh:=y1+b*t;
if (yh>max(y1,y2)) or (yh<min(y1,y2)) then exit(oo)
else exit(kc(x,y,xh,yh));
end;
procedure solve;
var
i,j:longint;
begin
kq:=oo;
for i:=1 to n do
for j:=1 to m do
kq:=min(kq,kc(x1[i],y1[i],x2[j],y2[j]));
for i:=1 to n-1 do
for j:=1 to m-1 do
begin
kq:=min(kq,dist(x1[i],y1[i],x2[j],y2[j],x2[j+1],y2[j+1]));
kq:=min(kq,dist(x2[j],y2[j],x1[i],y1[i],x1[i+1],y1[i+1]));
end;
end;
begin
openF;
inp;
solve;
ans;
closeF;
end.