| ||||||||||
| 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 | |||||||||
为什么我总是Run time error....我自己测所有的数据可能情况.都没有出现Run time error....
这个是我的程序.
type
word=longint;
integer=longint;
const
fx:array[1..8] of integer=(-1,1,-2,2,-2,2,-1,1);
fy:array[1..8] of integer=(-2,-2,-1,-1,1,1,2,2);
maxn=34;
var
a:array[1..maxn,1..maxn] of boolean;
m,n,time,t,nowx,nowy,tx,ty,i,j,k,tt:longint;
pathx,pathy,temp:string;
flag:boolean;
Procedure init;
begin
fillchar(a,sizeof(a),false);
read(m,n);
for i:=1 to m do
for j:=1 to n do a[i,j]:=true;
end;
Procedure print;
var
tt,code:integer;
begin
writeln('Scenario #',time,':');
for i:=1 to length(pathx) do
begin
val(pathy[i],tt,code);
write(chr(tt+ord('A')-1),pathx[i]);
end;
writeln;
writeln;
flag:=true;
end;
Procedure try(dep:integer);
var
i:integer;
begin
if flag then exit;
for i:=1 to 8 do
begin
tx:=nowx+fx[i];
ty:=nowy+fy[i];
if (tx in [1..m])and(ty in [1..n]) then
if a[tx,ty] then
begin
nowx:=tx;
nowy:=ty;
a[tx,ty]:=false;
inc(dep);
str(nowx,temp);
pathx:=pathx+temp;
str(nowy,temp);
pathy:=pathy+temp;
if dep=m*n then print else try(dep);
a[nowx,nowy]:=true;
nowx:=nowx-fx[i];
nowy:=nowy-fy[i];
delete(pathx,length(pathx),1);
delete(pathy,length(pathy),1);
dec(dep);
if flag then exit;
end;
end;
end;
Procedure main;
begin
nowx:=1;
nowy:=1;
pathx:='1';
pathy:='1';
a[1,1]:=false;
flag:=false;
try(1);
end;
Begin
read(tt);
for time:=1 to tt do
begin
init;
if (n<>1)or(m<>1) then
begin
main;
if not flag then
begin
writeln('Scenario #',time,':');
writeln('impossible');
writeln;
end;
end
else
begin
writeln('Scenario #',time,':');
writeln('A1');
writeln;
end;
end;
End.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator