codevs1024

题目地址: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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值