题目地址:http://codevs.cn/problem/1024/
分析:
最短路径
代码:
const oo=1000000000;
var
x,y:array[1..10] of longint;
n,m,t,k,i,j,a,b,x1,y1,x2,y2:longint;
f:array[1..120,1..120] of longint;
procedure swap(var l,r:longint);
var tmp:longint;
begin
tmp:=l;
l:=r;
r:=tmp;
end;
begin
read(n,m,t,k);
for i:=1 to 10 do;
for i:=1 to n do read(x[i]);
for j:=1 to m do read(y[j]);
for i:=1 to n*m do
for j:=1 to n*m do
if i=j then f[i][j]:=0
else f[i][j]:=oo;
for i:=1 to n do
for j:=1 to m do
begin
if i>1 then
begin
a:=i-1;b:=j;
f[(j-1)*n+i][(b-1)*n+a]:=x[i]-x[i-1];
end;
if j>1 then
begin
a:=i; b:=j-1;
f[(j-1)*n+i][(b-1)*n+a]:=y[j]-y[j-1];
end;
if i<n then
begin
a:=i+1;b:=j;
f[(j-1)*n+i][(b-1)*n+a]:=x[i+1]-x[i];
end;
if j<m then
begin
a:=i; b:=j+1;
f[(j-1)*n+i][(b-1)*n+a]:=y[j+1]-y[j];
end;
end;
for i:=1 to t do
begin
read(x1,y1,x2,y2);
f[(y1-1)*n+x1][(y2-1)*n+x2]:=oo;
f[(y2-1)*n+x2][(y1-1)*n+x1]:=oo;
end;
for i:=1 to k do
begin
read(x1,x2,y1,y2);
for a:=x1 to x2-1 do
for b:=y1+1 to y2-1 do
begin
f[(b-1)*n+a][(b-1)*n+a+1]:=oo;
f[(b-1)*n+a+1][(b-1)*n+a]:=oo;
end;
for b:=y1 to y2 -1 do
for a:=x1+1 to x2-1 do
begin
f[(b-1)*n+a][b*n+a]:=oo;
f[b*n+a][(b-1)*n+a]:=oo;
end;
end;
for k:=1 to n*m do
for i:=1 to n*m do
for j:=1 to n*m do
if f[i][k]+f[k][j]<f[i][j] then f[i][j]:=f[i][k]+f[k][j];
read(x1,y1,x2,y2);
writeln(f[(y1-1)*n+x1][(y2-1)*n+x2]);
end.