这题好像1539。

P2385 [USACO07FEB] Bronze Lilypad Pond B

ghruik @ 2017-09-20 11:19:58

同样的代码,都可以AC

var     a:array[1..1000,1..1000] of longint;
sum:array[1..1000,1..1000] of longint;
    b,c:array[1..8] of longint;
    q,n,m,x,y,i,j:longint;
    xxx,yyy:array[1..100000] of longint;
procedure sxw;
var i,j:longint;
begin
for i:=1 to n do
 for j:=1 to m do
  if a[i,j]=4 then begin writeln(sum[i,j]);halt;end;
end;
procedure ycl;
var i,j:longint;
begin
for i:=1 to n do
 for j:=1 to m do
  sum[i,j]:=maxlongint;
  sum[xxx[1],yyy[1]]:=0;
end;
procedure dd(k:longint);
var x,y,i:longint;
begin
if k>q then exit;
for i:=1 to 8 do
begin
x:=xxx[k]+b[i];y:=yyy[k]+c[i];
if (x>0)and(x<=n)and(y>0)and(y<=m) then
if ((a[x,y]=1)or(a[x,y]=4)) and (sum[x,y]>sum[xxx[k],yyy[k]]+1) then begin
sum[x,y]:=sum[xxx[k],yyy[k]]+1;
inc(q);
xxx[q]:=x;
yyy[q]:=y;
end;
end;
dd(k+1);
end;
begin
readln(n,m,x,y);
for i:=1 to n do
 for j:=1 to m do
 begin
read(a[i,j]);
if a[i,j]=3 then begin xxx[1]:=i;yyy[1]:=j;end;
end;
b[1]:=x;
b[2]:=y;
b[3]:=-y;
b[4]:=-x;
b[5]:=-x;
b[6]:=-y;
b[7]:=y;
b[8]:=x;
c[1]:=y;
c[8]:=-y;
c[2]:=x;
c[7]:=-x;
c[3]:=x;
c[6]:=-x;
c[4]:=y;
c[5]:=-y;
q:=1;
ycl;
dd(1);
sxw;
end.

by yan_jun @ 2022-08-10 16:21:02

%%%%%%%


|