Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求助,双向BFS超时

Posted by chm1994 at 2010-10-04 15:57:53 on Problem 1915
各位牛帮忙看看哪里错了
const
  maxn=90000;
  dx:array[1..8]of longint=(-1,-1,-2,-2,1,1,2,2);
  dy:array[1..8]of longint=(-2,2,-1,1,-2,2,-1,1);
type
  ass=record
  x,y,g:longint;
  end;

var
t,h:array[0..1]of longint;
troop:array[0..1,1..90001]of ass;
ttt,tt,l,i,x1,y1,x2,y2:longint;
f:array[0..1,0..299,0..299]of 0..1;
yes:boolean;
procedure add(xx:longint);
var  i,ii,nowx,nowy:longint;
     now:ass;
begin
inc(h[xx]);
now:=troop[xx,h[xx]];
for i:=1 to 8 do
 begin
 nowx:=now.x+dx[i];
 nowy:=now.y+dy[i];
 if (nowx>=0)and (nowx<=l-1)and (nowy>=0)and (nowy<=l-1)and(f[xx,nowx,nowy]=0)
   then
    begin
    inc(t[xx]);
    troop[xx,t[xx]].x:=nowx;
    troop[xx,t[xx]].y:=nowy;
    troop[xx,t[xx]].g:=now.g+1;
    f[xx,nowx,nowy]:=1;
    for ii:=1 to t[1-xx] do
     if (troop[1-xx,ii].x=troop[xx,t[xx]].x)and (troop[1-xx,ii].y=troop[xx,t[xx]].y)then
     begin
      writeln(troop[1-xx,ii].g+troop[xx,t[xx]].g);
      yes:=true;
      exit;
     end;
   end;
  end;
end;
begin
readln(tt);
for ttt:=1 to tt do
 begin
  readln(l);
  readln(x1,y1);
  readln(x2,y2);
  if (x1=x2)and (y1=y2)then begin  writeln(0); continue;end;
  for i:=1 downto 0 do  begin t[i]:=1; h[i]:=0; end;
  troop[0,1].x:=x1;
  troop[0,1].y:=y1;
  troop[1,1].x:=x2;
  troop[1,1].y:=y2;
  fillchar(f,sizeof(f),0);
  f[0,x1,y1]:=1;
  f[1,x2,y2]:=1;
 yes:=false;
  repeat
   if (t[0]<=t[1]) and not((h[0]>=t[0])or(t[0]>=maxn))then add(0);
   if yes then break;
   if (t[1]<=t[0]) and not((h[1]>=t[1])or(t[1]>=maxn))then add(1);
   if yes then break;
   if  not((h[0]>=t[0])or(t[0]>=maxn))then add(0);
   if yes then break;
   if  not((h[1]>=t[1])or(t[1]>=maxn))then add(1);
  until ((h[1]>=t[1])or(t[1]>=maxn))and ((h[0]>=t[0])or (t[0]>=maxn)) or yes;
 end;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator