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 |
Re:求0s代码In Reply To:Re:求0s代码 Posted by:scau_200930740601 at 2010-07-17 21:43:53 type newtype=record x,y,z:longint; end; const maxn=30; dx:array[1..6] of longint=(0,0,0,0,1,-1); dy:array[1..6] of longint=(0,0,1,-1,0,0); dz:array[1..6] of longint=(1,-1,0,0,0,0); var t,n,m:longint; st,ed:newtype; g:array[1..maxn,1..maxn,1..maxn] of char; h:array[1..maxn,1..maxn,1..maxn] of boolean; q:array[1..maxn*maxn*maxn] of newtype; s:array[1..maxn*maxn*maxn] of longint; procedure init; var i,j,k:longint; begin for i:=1 to t do begin for j:=1 to n do begin for k:=1 to m do begin read(g[j,k,i]); if g[j,k,i]='S' then begin st.x:=j;st.y:=k;st.z:=i; end else if g[j,k,i]='E' then begin ed.x:=j;ed.y:=k;ed.z:=i; end; end; readln; end; readln; end; end; procedure bfs; var i,tx,ty,tz,l,r:longint; begin l:=0;r:=1; fillchar(q,sizeof(q),0); fillchar(s,sizeof(s),0); fillchar(h,sizeof(h),1); q[1]:=st; h[st.x,st.y,st.z]:=false; while l<r do begin inc(l); for i:=1 to 6 do begin tx:=q[l].x+dx[i]; ty:=q[l].y+dy[i]; tz:=q[l].z+dz[i]; if (tx>0) and (ty>0) and (tz>0) and (tx<=n) and (ty<=m) and (tz<=t) then if (h[tx,ty,tz]) and (g[tx,ty,tz]<>'#') then begin inc(r); q[r].x:=tx; q[r].y:=ty; q[r].z:=tz; s[r]:=s[l]+1; h[tx,ty,tz]:=false; if (q[r].x=ed.x) and (q[r].y=ed.y) and (q[r].z=ed.z) then begin writeln('Escaped in ',s[r],' minute(s).'); exit; end; end; end; end; writeln('Trapped!'); end; begin readln(t,n,m); while (t<>0) and (n<>0) and (m<>0) do begin init; bfs; readln(t,n,m); end; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator