社区讨论
为什么WA了,急
P1443马的遍历参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mi6mocd3
- 此快照首次捕获于
- 2025/11/20 07:22 4 个月前
- 此快照最后确认于
- 2025/11/20 07:22 4 个月前
CPP
const
fx:array[1..8]of longint=(1,2,-1,-2,1,2,-1,-2);
fy:array[1..8]of longint=(2,1,2,1,-2,-1,-2,-1);
var
map:array[1..400,1..400]of longint;
father,x,y:array[1..1000]of longint;
i,j,n,m,sx,sy:longint;
function check(a,b:longint):boolean;
begin
if (a>=1)and(a<=n)and(b>=1)and(b<=m)and(map[a,b]=-1) then exit(true);
exit(false);
end;
procedure bfs;
var i,head,tail,xx,yy:longint;
begin
x[1]:=sx; y[1]:=sy;
head:=0; tail:=1;
map[sx,sy]:=0;
repeat
inc(head);
for i:=1 to 8 do
if check(x[head]+fx[i],y[head]+fy[i]) then
begin
xx:=x[head]+fx[i]; yy:=y[head]+fy[i];
father[head]:=tail;
inc(tail);
x[tail]:=xx; y[tail]:=yy;
map[xx,yy]:=map[x[head],y[head]]+1;
end;
until(head=tail);
end;
begin
read(n,m,sx,sy);
for i:=1to n do
for j:=1 to m do
map[i,j]:=-1;
bfs;
map[sx,sy]:=0;
for i:=1 to n do
begin
for j:=1 to m do
write(map[i,j],' ');
writeln;
end;
end.
回复
共 0 条回复,欢迎继续交流。
正在加载回复...