📄 lift.pas
字号:
var n,i,j,l,a,b,p:longint;
lift,step:array[0..200] of longint;
begin
assign(input,'lift.in');
reset(input);
assign(output,'lift.out');
rewrite(output);
read(n,a,b);
for i:=1 to n do read(lift[i]);
for i:=1 to n do step[i]:=-1;
step[a]:=0;
p:=0; l:=1;
while (l>0) and (step[b]=-1) do
begin
l:=0;
for i:=1 to n do
if step[i]=p then
begin
j:=i-lift[i];
if (j>0) and (step[j]=-1) then
begin
step[j]:=p+1;
l:=l+1;
end;
j:=i+lift[i];
if (j<=n) and (step[j]=-1) then
begin
step[j]:=p+1;
l:=l+1;
end;
end;
p:=p+1;
end;
write(step[b]);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -