|
|
back to boardI think mine is right,butЎ­Ў­,please help me! Posted by fyrs 26 Jul 2003 20:37 this is my program: type node=record x,y:shortint; end; var n:byte; a:array[1..10,1..10] of record visited:boolean; black:boolean; end; l,b:byte; f:array[1..4] of node; ch:array[1..4] of char; procedure init; var i:byte; tx,ty:byte; begin readln(n); fillchar(a,sizeof(a),0); l:=11; for i:=1 to n do begin readln(tx,ty); a[tx,ty].black:=true; if tx<l then begin l:=tx; b:=ty end else if (tx=l) and (ty<b) then b:=ty; end; f[1].x:=1;f[1].y:=0; f[2].x:=0;f[2].y:=1; f[3].x:=-1;f[3].y:=0; f[4].x:=0;f[4].y:=-1; ch[1]:='R';ch[2]:='T';ch[3]:='L';ch[4]:='B'; end; procedure bfs(x,y:byte); var open,closed:byte; bf:array[1..100] of node; i,tx,ty:shortint; begin open:=1;closed:=0; bf[1].x:=x;bf[1].y:=y; a[x,y].visited:=true; repeat inc(closed); for i:=1 to 4 do begin tx:=bf[closed].x+f[i].x; ty:=bf[closed].y+f[i].y; if (tx in [1..10]) and (ty in [1..10]) and (a[tx,ty].black) and (not a[tx,ty].visited) then begin inc(open); bf[open].x:=tx;bf[open].y:=ty; a[tx,ty].visited:=true; write(ch[i]); end; end; if closed<open then writeln(',') else writeln('.'); until closed>=open; end; begin init; writeln(l,' ',b); bfs(l,b); end. |
|
|