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 |
Help! Where does it wrong?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator