求一条路径,不能经过规定的危险区域。
超级暴力枚举,每次判断两点之间是否可以连线,用计算几何算是否有交点。
没ac,70分的
type
Point=record
x,y:real;
end;
const
maxn=300;
var
a:array [1..maxn] of longint;
f:array [1..maxn,1..2] of longint;
s:array [1..maxn,1..maxn] of real;
i,j,n,x,y,p,k:longint;
e,b,c,d:Point;
function max(x,y:real):real;
begin
if x>y then exit(x)
else exit(y);
end;
function min(x,y:real):real;
begin
if x>y then exit(y)
else exit(x);
end;
function mult(a,b,c:Point):double;
begin
exit((a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y));
end;
function kua(aa,bb,cc,dd:Point):boolean;
begin
if (max(aa.x, bb.x) <= min(cc.x, dd.x)) then
begin
exit(false);
end;
if (max(aa.y, bb.y) <= min(cc.y, dd.y)) then
begin
exit(false);
end;
if (max(cc.x, dd.x) <= min(aa.x, bb.x)) then
begin
exit(false);
end;
if (max(cc.y, dd.y) <= min(aa.y, bb.y)) then
begin
exit(false);
end;
if (mult(cc, bb, aa)*mult(bb, dd, aa)<=0) then
begin
exit(false);
end;
if (mult(aa, dd, cc)*mult(dd, bb, cc)<=0) then
begin
exit(false);
end;
exit(true);
end;
function cheak(x1,y1,x2,y2:longint):boolean;
var
i,j,k,sum:longint;
begin
sum:=0;
for i:=1 to n do
begin
for j:=1 to a[i] do
for k:=j+2 to a[i] do
begin
e.x:=x1; e.y:=y1;
b.x:=x2; b.y:=y2;
c.x:=f[sum+j,1]; c.y:=f[sum+j,2];
d.x:=f[sum+k,1]; d.y:=f[sum+k,2];
if kua(e,b,c,d) then exit(false);
end;
sum:=sum+a[i];
end;
exit(true);
end;
begin
readln(n);
for i:=1 to maxn do
for j:=1 to maxn do
s[i,j]:=999999999;
for i:=1 to n do
begin
readln(a[i]);
for j:=1 to a[i] do
begin
inc(p);
readln(f[p,1],f[p,2]);
end;
end;
for i:=1 to p do
for j:=i+1 to p do
if cheak(f[i,1],f[i,2],f[j,1],f[j,2]) then
begin
s[i,j]:=sqrt(sqr(f[i,1]-f[j,1])+sqr(f[i,2]-f[j,2]));
s[j,i]:=s[i,j];
end;
for i:=1 to p do
for j:=1 to p do
if i<>j then
for k:=1 to p do
if s[i,j]>s[i,k]+s[k,j] then
s[i,j]:=s[i,k]+s[k,j];
readln(x,y);
writeln(s[x,y]:0:4)
end.