状态题目:紧急援救
题目编号:34-紧急援救 查看该题
状态: Accepted
测评机: Xeond[6]
得分: 100分
提交日期: 2008-8-20 20:01:00
有效耗时: 2017毫秒
测试结果1: 通过本测试点|有效耗时172:ms
测试结果2: 通过本测试点|有效耗时47:ms
测试结果3: 通过本测试点|有效耗时297:ms
测试结果4: 通过本测试点|有效耗时219:ms
测试结果5: 通过本测试点|有效耗时219:ms
测试结果6: 通过本测试点|有效耗时250:ms
测试结果7: 通过本测试点|有效耗时94:ms
测试结果8: 通过本测试点|有效耗时219:ms
测试结果9: 通过本测试点|有效耗时250:ms
测试结果10: 通过本测试点|有效耗时250:ms
const c:array[1..4,1..2] of longint=((-1,0),(1,0),(0,1),(0,-1));
var n,x,y,x1,y1,x2,y2:longint;
a:array[0..1001,0..1001] of char;
b:array[0..1000000,1..3] of longint;
procedure init;
var i,j:longint;
begin
readln(n);
for i:=1 to n do
begin
for j:=1 to n do read(a[i,j]); readln;
end;
readln(x1,y1); readln(x2,y2);
end;
procedure work;
var i,tp1,tp2:longint;
begin
tp1:=1; tp2:=1;
fillchar(b,sizeof(b),0);
a[x1,y1]:=’1’; b[1,1]:=x1; b[1,2]:=y1;
while tp1<=tp2 do
begin
x:=b[tp1,1]; y:=b[tp1,2];
for i:=1 to 4 do
begin
x:=x+c[i,1]; y:=y+c[i,2];
if (x>0) and (x<=n)and (y>0)and (y<=n)and (a[x,y]=’0’) then
begin
inc(tp2);
b[tp2,1]:=x; b[tp2,2]:=y;
b[tp2,3]:=b[tp1,3]+1;
a[x,y]:=’1’;
if (x=x2)and (y=y2) then begin writeln(b[tp2,3]); halt; end;
end;
x:=x-c[i,1]; y:=y-c[i,2];
end;
inc(tp1);
end;
end;
begin
init;
work;
end.