- 笨笨的纸条传递
- 2009-01-23 23:00:00 @
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案错误...程序输出比正确答案长
├ 测试数据 04:答案错误...程序输出比正确答案长
├ 测试数据 05:答案错误...程序输出比正确答案长
├ 测试数据 06:答案错误...程序输出比正确答案长
├ 测试数据 07:答案错误...程序输出比正确答案长
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Unaccepted 有效得分:50 有效耗时:0ms
程序如下:
program T1039_4;
const
filein='T1039_4.in';
fileout='T1039_4.out';
maxn=30;
perx:array[1..4]of -1..1=(1,0,-1,0);
pery:array[1..4]of -1..1=(0,1,0,-1);
maxlongint=10000000;
type
Tin=longint;
Tarr=array[1..maxn,1..maxn]of Tin;
Tarr2=array[0..maxn+1,0..maxn+1]of boolean;
var
x1,x2,y1,y2,start,own,time,sx,sy,timen:Tin;
man,cla:Tarr;
pd:Tarr2;
procedure init;
var
i,j:Tin;
begin
readln(x1,y1);
for i:=1 to x1 do
begin
for j:=1 to y1 do
begin
read(man);
if man=0
then begin
sx:=i;
sy:=j;
end;
end;
readln;
end;
readln(x2,y2);
for i:=x2 downto 1 do
begin
for j:=1 to y2 do
begin
read(cla);
if cla=0
then own:=i*y2+j;
end;
readln;
end;
readln(start);
end;
procedure dfs(nx,ny,num:Tin);
var
i,min,minx,miny,t:Tin;
begin
if num=x1*y1
then begin
writeln(num);
writeln(nx,',',ny);
exit;
end;
min:=maxlongint;
t:=0;
for i:=1 to 4 do
if pd[nx+perx[i],ny+pery[i]]
then begin
if man[nx+perx[i],ny+pery[i]]time
then begin
writeln('Error!');
writeln(minx,',',miny);
exit;
end
else begin
inc(timen,min);
pd[minx,miny]:=false;
dfs(minx,miny,num+1);
end;
end;
procedure main;
var
i,j,x,y:Tin;
begin
timen:=0;
fillchar(pd,sizeof(pd),false);
for i:=1 to x1 do
for j:=1 to y1 do
pd:=true;
time:=0;
if start=0
then for i:=1 to own do
begin
x:=i div y2;
y:=i mod y2;
if y=0
then begin
dec(x);
y:=y2;
end;
inc(time,cla[x,y]);
end
else for i:=1 to own do
begin
x:=i div y2;
y:=i mod y2;
if y=0
then begin
dec(x);
y:=y2;
end;
inc(time,cla[x,y2-y+1]);
end;
pd[sx,sy]:=false;
dfs(sx,sy,1);
end;
begin
init;
main;
end.
请各路牛人帮下忙!谢