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

Help! Where does it wrong?

Posted by sxd31415926 at 2011-07-04 14:50:37 on Problem 3278
var
        flag:array[1..210000]of boolean;
        q:array[0..210000]of longint;
        dist:array[1..210000]of longint;
        v,h,t,n,m,i:longint;
begin
        readln(n,m); fillchar(flag,sizeof(flag),0); flag[n]:=true;
        fillchar(dist,sizeof(dist),127); dist[n]:=0;
        h:=0; t:=1; q[t]:=n;
        while h<>t do
         begin
                h:=(h+1) mod 210001; v:=q[h]; flag[v]:=false;
                if (dist[v+1]>dist[v]+1)and(v+1<=210000) then
                 begin
                        dist[v+1]:=dist[v]+1;
                        if not flag[v+1] then
                         begin
                                t:=(t+1) mod 210001;
                                q[t]:=v+1; flag[v+1]:=true;
                         end;
                 end;
                if (dist[v-1]>dist[v]+1)and(v-1>0) then
                 begin
                        dist[v-1]:=dist[v]+1;
                        if not flag[v-1] then
                         begin
                                t:=(t+1) mod 210001;
                                q[t]:=v-1; flag[v-1]:=true;
                         end;
                 end;
                if (v shl 1<=210000)and(dist[v shl 1]>dist[v]+1) then
                 begin
                        dist[v shl 1]:=dist[v]+1;
                        if not flag[v shl 1] then
                         begin
                                t:=(t+1) mod 210001;
                                q[t]:=v shl 1; flag[v shl 1]:=true;
                         end;
                 end;
         end;
        writeln(dist[m]);
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