| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
...为什么会Runtime Error???????大牛帮我看看。。什么问题么?program p1915;
const move:array[1..8,1..2]of shortint=((1,2),(2,1),(2,-1),(1,-2),
(-1,-2),(-2,-1),(-2,1),(-1,2));
var chart:array[0..300,0..300]of boolean;
list:array[1..10000,1..2]of longint;
num,n:longint;
size,total,step:longint;
goal:array[1..2]of longint;
procedure init;
begin
readln(size);
readln(list[1,1],list[1,2]);
readln(goal[1],goal[2]);
chart[list[1,1],list[1,2]]:=true;
total:=1;
step:=0
end;
procedure main;
var head,tail,i:longint;
begin
head:=1; tail:=0;
while tail<head do
begin
inc(tail);
for i:=1 to 8 do
if (list[tail,1]+move[i,1]>=0) and (list[tail,1]+move[i,1]<size+1)
and (list[tail,2]+move[i,2]>=0) and (list[tail,2]+move[i,2]<size+1)
and (not chart[list[tail,1]+move[i,1],list[tail,2]+move[i,2]]) then
begin
inc(total);
list[total,1]:=list[tail,1]+move[i,1];
list[total,2]:=list[tail,2]+move[i,2];
chart[list[total,1],list[total,2]]:=true;
if (goal[1]=list[total,1]) and (goal[2]=list[total,2]) then
begin
writeln(step+1);
exit;
end;
end;
if (tail=head) and (head<total) then
begin inc(step); head:=total; end;
end;
end;
begin
readln(num);
for n:=1 to num do
begin
fillchar(chart,sizeof(chart),#0);
init;
if (list[1,1]=goal[1]) and (list[1,2]=goal[2]) then writeln(0)
else main;
end;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator