讨论 / 求解释
球威 2012-01-14 03:32:00
点我顶贴 收藏 删除
状态: Unaccepted

测评机: Xeost[5]

得分: 90分

提交日期: 2012-1-14 19:30:00

有效耗时: 2360毫秒

测试结果1: 通过本测试点|有效耗时156ms

测试结果2: 通过本测试点|有效耗时156ms

测试结果3: 测试结果错误.错误结果为:841

正确结果应为:1065

测试结果4: 通过本测试点|有效耗时282ms

测试结果5: 通过本测试点|有效耗时266ms

测试结果6: 通过本测试点|有效耗时312ms

测试结果7: 通过本测试点|有效耗时266ms

测试结果8: 通过本测试点|有效耗时281ms

测试结果9: 通过本测试点|有效耗时313ms

测试结果10: 通过本测试点|有效耗时328ms

#1 球威@2012-01-14 03:32:00
回复 删除
代码:

program iue;

type

rec=record

x,y:longint;

step:longint;

end;

var

map:array[1..1001,1..1001]of char;

i,j,k,n,x,y,x2,y2:longint;

p,q:longint;

ch:char;

ok:boolean;

now:array[1..1000001]of rec;

procedure move(a,b:longint);

begin

if(now[p].x+a>n)or(now[p].x+a<1)or

(now[p].y+b>n)or(now[p].y+b>n)then exit;

now[q].x:=now[p].x+a;

now[q].y:=now[p].y+b;

now[q].step:=now[p].step+1;

if map[now[q].x,now[q].y]=#2 then exit;

if map[now[q].x,now[q].y]='1' then exit;

if map[now[q].x,now[q].y]=#1then ok:=true;

if not ok then map[now[q].x,now[q].y]:=#2;

inc(q);

end;

procedure work;

begin

now[1].x:=x;now[1].y:=y;now[1].step:=0;

p:=1;q:=2;ok:=false;

repeat

move(1,0);move(0,1);

move(-1,0);move(0,-1);

if ok then break;

inc(p);

{for i:=1 to n do begin

for j:=1 to n do write(map[i,j]);

writeln;

end;}

until ok or(p=q);

end;

procedure print;

begin

if ok then begin

while map[now[q].x,now[q].y]<>#1 do dec(q);

write(now[q].step);

end;

end;

begin

readln(n);

for i:=1 to n do begin

for j:=1 to n do read(map[i,j]);

readln;

end;

read(x,y);

read(x2,y2);map[x2,y2]:=#1;

work;

print;

end.

查看更多回复
提交回复