#include<stdio.h> int map[101][101]; int x,y; int sx,sy; int now; int n; int stack[3][101]; int ps,pe; int push(int x,int y) { stack[1][ps]=x; stack[2][ps]=y; ps++; return 0; } int gen(int x,int y) { int tmp; now++; if(map[y][x+1]==1) { printf("R"); map[y][x+1]=0; push(x+1,y); } if(map[y+1][x]==1) { printf("T"); map[y+1][x]=0; push(x,y+1); } if(map[y][x-1]==1) { printf("L"); map[y][x-1]=0; push(x-1,y); } if(map[y-1][x]==1) { printf("B"); map[y-1][x]=0; push(x,y-1); } if(now<n) printf(",\n"); else printf(".\n"); while(pe!=ps) { tmp=pe; pe++; gen(stack[1][tmp],stack[2][tmp]); } return 0; } int main() { int i; scanf("%d",&n); scanf("%d%d",&sx,&sy); for(i=2;i<=n;i++) { scanf("%d%d",&x,&y); map[y][x]=1; } printf("%d %d\n",sx,sy); now=0; gen(sx,sy); return 0; } Can somebody kindly give me some tests? I can not pass Test #2. I don't know the reason. Thanks in advance. Dear Admins! There are some grammar mistakes in the problem statement. Fix them please. {$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R+,S+,T-,V+,X+,Y+} {$M 16384,0,655360} Const Maxn= 20; dx : Array[1..4] Of Integer =( 1,0,-1, 0); dy : Array[1..4] Of Integer =( 0,1, 0,-1); Nb : Array[1..4] Of Char =('R','T','L','B'); Var Matrix: Array[0..Maxn+1, 0..Maxn+1] Of Boolean; n: Integer; i, j, t: Integer; minx, miny: Integer; Procedure Print2; Var Queuex, Queuey: Array[1..Maxn*Maxn] Of Integer; Front, Rear: Integer; x, y, count, i: Integer; ch: Char; st: String; Begin FillChar(Matrix, SizeOf(Matrix), False); Queuex[1]:= minx; Queuey[1]:= miny; Front:= 1; Rear:= 1; Matrix[minx, miny]:= True; count:= 1; While Rear<= Front Do Begin x:= Queuex[Rear]; y:= Queuey[Rear]; Inc(Rear); Readln(st); i:= 1; While st[i]<>',' Do Begin Case upcase(st[i]) Of 'R':Begin Inc(Front); Queuex[Front]:= x+ dx[1]; Queuey[Front]:= y+ dy[1]; Matrix[x+dx[1], y+dy[1]]:= True; inc(Count); End; 'T':Begin Inc(Front); Queuex[Front]:= x+ dx[2]; Queuey[Front]:= y+ dy[2]; Matrix[x+dx[2], y+dy[2]]:= True; inc(Count); End; 'L':Begin Inc(Front); Queuex[Front]:= x+ dx[3]; Queuey[Front]:= y+ dy[3]; Matrix[x+dx[3], y+dy[3]]:= True; inc(Count); End; 'B':Begin Inc(Front); Queuex[Front]:= x+ dx[4]; Queuey[Front]:= y+ dy[4]; Matrix[x+dx[4], y+dy[4]]:= True; inc(Count); End; '.': Break; End; inc(i); End; End; Writeln(Count); For x:= 1 To Maxn Do For y:= 1 To Maxn Do If Matrix[x, y] Then Writeln(x,' ', y); End; Procedure Print1; Var Queuex, Queuey: Array[1..Maxn*Maxn] Of Integer; x, y, k: Integer; Front, Rear: Integer; first: Boolean; Begin Writeln(minx, ' ', miny); Queuex[1]:= minx; Queuey[1]:= miny; Front:= 1; Rear:= 1; Matrix[minx, miny]:= False; First:= True; While Rear<= Front Do Begin If Not First Then Writeln(',') Else First:= False; x:= Queuex[Rear]; y:= Queuey[Rear]; Inc(Rear); For k:=1 To 4 Do If Matrix[x+dx[k], y+dy[k]] Then Begin Write(Nb[k]); Matrix[x+dx[k], y+dy[k]]:= False; Inc(Front); Queuex[Front]:= x+dx[k]; Queuey[Front]:= y+ dy[k] End; End; Writeln('.'); End; Var st: string; Begin st:=''; Read(n); If Eoln Then Begin FillChar(Matrix, SizeOf(Matrix), False); minx:= Maxint; miny:= minx; For i:=1 To n Do Begin Readln(j, t); If (j= Minx) And (t< Miny) Then Miny:= t; If (j< Minx) ANd (t= Miny) Then Minx:= j; If (j< Minx) And (t< Miny) Then Begin minx:= j; miny:= t; End; Matrix[j, t]:= True; End; Print1; End Else Begin minx:= n; Readln(miny); Print2; End; End. I tried with many test, It all returned the true answer but not to be accepted. Delete this {$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R+,S+,T-,V+,X+,Y+} {$M 16384,0,655360} And you'll get AC! I have got AC. I have repaired it for all today'afternoon but found nothing. Can you explain to me why my program got wrong with some directive compilers, It should be warned in FAQ. In my timus programs I've never used any directive compilers, except {$M 16777216}, so in this question I can't help you! )) Because of you use {$M 16384,0,655360} directive which have the next syntax: {$M minstacksize,maxstacksize} or {$M reservedbytes} for Linux Maybe they should have written "left lower" Do we have to print neighbour lists for ALL black pixels. Suppose it like this: One pixel has two neighbours and that's all. We output a line for the first pixel and end it with '.'. There is no need actually to output the lists for other pixels, since we don't get any additional information... Can anyone tell me why I get WA on the second test? And I have two more questions: 1.) The coordinates that I have to output are always on the second line of the input file, aren't they? 2.) Can there be more than one image in one test file? (e.g.: 2 1 1 5 5 ) Edited by author 28.06.2006 22:50 Edited by author 28.06.2006 22:55 Nevermind...I solved the problem (I didn't understand that I can get any representation of the image in the input file). First I also understand problem wrong. I remade my solution, but get wrong answer again :( I think that Sample Input and Output very bad and programmer cannot understand the problem completely. Mr. goodbye boy or somebody! Can you say, does this answer right for this input? Input: 8 2 3 2 4 2 5 2 6 3 3 3 4 4 2 4 3 Output: RT, RT, T, B, , , T, . If this is wrong, please say the right. Thanks. i think it's wrong. I THINK the right is RT, RT, T, B, , T, , . BUT I'M NOT SURE. > i think it's wrong. > I THINK the right is > RT, > RT, > T, > B, > , > T, > , > . > BUT I'M NOT SURE. > > i think it's wrong. > > I THINK the right is > > RT, > > RT, > > T, > > B, > > , > > T, > > , > > . > > BUT I'M NOT SURE. I Got the same result,but where is the first line with "2 3"? And my program hasn't been accepted now, who can help me by giving some more testing data? I agree with it: 2 3 RT, RT, T, B, , T, , . > i think it's wrong. > I THINK the right is > RT, > RT, > T, > B, > , > T, > , > . > BUT I'M NOT SURE. RT, RT, T, B, , T, , . this anwer gives my AC program Input may be that: 6 2 3 2 4 3 3 3 4 4 2 4 3 and that: 2 3 RT, RT, , B, , . It's true or not???? Yes input is the one of two representations of an image This is my code. [code deleted] Edited by moderator 20.04.2006 00:24 const f: array [1..4, 1..2] of integer = ((1, 0), (0, -1), (-1, 0), (0, 1)); str: array [1..4] of char = ('R', 'B', 'L', 'T'); var x, y, p: array [1..10] of longint; n, n0, i, j, k, head, foot, x0, y0, q: longint; ok: boolean; s: string; begin read(n); if eoln then begin for i := 1 to n do read(x[i], y[i]); head := 0; foot := 1; p[1] := 1; writeln(x[1], ' ', y[1]); repeat inc(head); for i := 1 to 4 do begin x0 := x[p[head]] + f[i, 1]; y0 := y[p[head]] + f[i, 2]; j := 1; while (j <= n) and ((x0 <> x[j]) or (y0 <> y[j])) do inc(j); if j > n then continue; ok := true; for k := 1 to foot do if j = p[k] then begin ok := false; break; end; if ok then begin write(str[i]); inc(foot); p[foot] := j; end; end; if head = n then writeln('.') else writeln(','); until head = n; end else begin x[1] := n; readln(y[1]); n0 := 1; n := 0; repeat inc(n); readln(s); for i := 1 to length(s) - 1 do for j := 1 to 4 do if s[i] = str[j] then begin inc(n0); x[n0] := x[n] + f[j, 1]; y[n0] := y[n] + f[j, 2]; break; end; if s[length(s)] = '.' then break; until false; for i := 1 to n - 1 do begin q := i; for j := i + 1 to n do if (x[j] < x[q]) or ((x[j] = x[q]) and (y[j] < y [q])) then q := j; if q <> i then begin x0 := x[q]; y0 := y[q]; x[q] := x[i]; y[q] := y[i]; x[i] := x0; y[i] := y0; end; end; writeln(n); for i := 1 to n do writeln(x[i], ' ', y[i]); end; end. > const > f: array [1..4, 1..2] of integer = > ((1, 0), (0, -1), (-1, 0), (0, 1)); > // str: array [1..4] of char = ('R', 'B', 'L', 'T'); this is clockwise order; the problem statement sais anticlockwise RTLB; > > var > x, y, p: array [1..10] of longint; > n, n0, i, j, k, head, foot, x0, y0, q: longint; > ok: boolean; > s: string; > > begin > read(n); > if eoln then begin > for i := 1 to n do read(x[i], y[i]); > head := 0; > foot := 1; > p[1] := 1; > writeln(x[1], ' ', y[1]); > repeat > inc(head); > for i := 1 to 4 do begin > x0 := x[p[head]] + f[i, 1]; > y0 := y[p[head]] + f[i, 2]; > j := 1; > while (j <= n) and ((x0 <> x[j]) or (y0 <> y[j])) > do inc(j); > if j > n then continue; > ok := true; > for k := 1 to foot do if j = p[k] then begin ok := > false; break; end; > if ok then begin > write(str[i]); > inc(foot); > p[foot] := j; > end; > end; > if head = n then writeln('.') else writeln(','); > until head = n; > end > else begin > x[1] := n; > readln(y[1]); > n0 := 1; > n := 0; > repeat > inc(n); > readln(s); > for i := 1 to length(s) - 1 do > for j := 1 to 4 do > if s[i] = str[j] then begin > inc(n0); > x[n0] := x[n] + f[j, 1]; > y[n0] := y[n] + f[j, 2]; > break; > end; > if s[length(s)] = '.' then break; > until false; > for i := 1 to n - 1 do begin > q := i; > for j := i + 1 to n do > if (x[j] < x[q]) or ((x[j] = x[q]) and (y[j] < y > [q])) then q := j; > if q <> i then begin > x0 := x[q]; > y0 := y[q]; > x[q] := x[i]; > y[q] := y[i]; > x[i] := x0; > y[i] := y0; > end; > end; > writeln(n); > for i := 1 to n do writeln(x[i], ' ', y[i]); > end; > end. > const > f: array [1..4, 1..2] of integer = > ((1, 0), (0, -1), (-1, 0), (0, 1)); > // str: array [1..4] of char = ('R', 'B', 'L', 'T'); > this is clockwise order; > the problem statement sais anticlockwise RTLB; I changed it into RTLB and also get WA!!! > const > f: array [1..4, 1..2] of integer = > ((1, 0), (0, -1), (-1, 0), (0, 1)); > str: array [1..4] of char = ('R', 'B', 'L', 'T'); > > var > x, y, p: array [1..10] of longint; > n, n0, i, j, k, head, foot, x0, y0, q: longint; > ok: boolean; > s: string; > > begin > read(n); > if eoln then begin > for i := 1 to n do read(x[i], y[i]); > head := 0; > foot := 1; > p[1] := 1; > writeln(x[1], ' ', y[1]); > repeat > inc(head); > for i := 1 to 4 do begin > x0 := x[p[head]] + f[i, 1]; > y0 := y[p[head]] + f[i, 2]; > j := 1; > while (j <= n) and ((x0 <> x[j]) or (y0 <> y[j])) > do inc(j); > if j > n then continue; > ok := true; > for k := 1 to foot do if j = p[k] then begin ok := > false; break; end; > if ok then begin > write(str[i]); > inc(foot); > p[foot] := j; > end; > end; > if head = n then writeln('.') else writeln(','); > until head = n; > end > else begin > x[1] := n; > readln(y[1]); > n0 := 1; > n := 0; > repeat > inc(n); > readln(s); > for i := 1 to length(s) - 1 do > for j := 1 to 4 do > if s[i] = str[j] then begin > inc(n0); > x[n0] := x[n] + f[j, 1]; > y[n0] := y[n] + f[j, 2]; > break; > end; > if s[length(s)] = '.' then break; > until false; > for i := 1 to n - 1 do begin > q := i; > for j := i + 1 to n do > if (x[j] < x[q]) or ((x[j] = x[q]) and (y[j] < y > [q])) then q := j; > if q <> i then begin > x0 := x[q]; > y0 := y[q]; > x[q] := x[i]; > y[q] := y[i]; > x[i] := x0; > y[i] := y0; > end; > end; > writeln(n); > for i := 1 to n do writeln(x[i], ' ', y[i]); > end; > end. i change 5 to 10 .. but i still wa... at this time i got wa on test 1 before i just got wa on test 2.... -____-b Watch out! It says: "There is at least one black pixel and all black pixels are connected with their sides" ... btw I got ACC :) can you put the pro here maybe it can't input 0 ... My Code: program ural1008; const maxn=5; turn:array[1..4] of integer=(maxn,1,-maxn,-1); outp:array[1..4] of char=('R','T','L','B'); var m,hash:array[1..maxn*maxn] of boolean; q:array[1..maxn*maxn] of integer; s:string; procedure rep1; var i,k,n,a,b,l,r:integer; begin val(s,n,k);readln(a,b);writeln(a,' ',b); m[maxn*(a-1)+b]:=true;l:=1;r:=1; q[l]:=maxn*(a-1)+b;hash[q[l]]:=true; for i:=2 to n do begin readln(a,b);m[maxn*(a-1)+b]:=true; end; while l<=r do begin for i:=1 to 4 do begin a:=q[l]+turn[i]; if (a>0)and(a<=maxn*maxn) then if (not hash[a])and(m[a]) then begin write(outp[i]);inc(r);q[r]:=a; hash[a]:=true; end; end; if l<>r then writeln(',') else writeln('.'); inc(l); end; end; procedure rep2; var i,a,b,k,l,r:integer; s1,s2:string; c:char; begin s1:='';i:=1; while s[i]<>' ' do begin s1:=s1+s[i];inc(i); end; s2:=copy(s,i+1,length(s)-i); val(s1,a,k);val(s2,b,k);l:=1;r:=1; q[l]:=maxn*(a-1)+b;hash[q[l]]:=true; m[q[l]]:=true; while l<=r do begin read(c);if c='.' then break; while c<>',' do begin case c of 'R':a:=q[l]+turn[1]; 'T':a:=q[l]+turn[2]; 'L':a:=q[l]+turn[3]; 'B':a:=q[l]+turn[4]; end; if not hash[a] then begin m[a]:=true;inc(r);q[r]:=a; end; read(c);if c='.' then break; end; if c='.' then break; inc(l);readln; end; writeln(r); for i:=1 to maxn*maxn do if m[i] then writeln(i div maxn+1,' ',i mod maxn); end; begin readln(s); fillchar(m,sizeof(m),false); fillchar(hash,sizeof(hash),false); if length(s)<=2 then rep1 else rep2; end. Thank you very much!! Faint............. I changed maxn=5 to maxn=10...and got AC... Does the problem say the map is 10*10???? of course it says.. but i still got wa..... There is statement “Neighbors are listed counter-clockwise starting with the right”. That means RBLT; However I AC my program when set order RTLB – opposite to clockwise!!!! Dear Veniamin, R = right, T - top, L - left, B - bottom, so RTLB IS counter-clockwise!!! Edited by author 28.03.2005 17:39 yes, I see. Sorry for my mistake. const max =10; var map :array[1..max,1..max] of boolean; n :integer; nei :array[1..1000000] of record x,y:integer; end; Procedure into; var i,a,b :integer; begin fillchar(map,sizeof(map),false); readln(n); readln(nei[1].x,nei[1].y); writeln(nei[1].x,' ',nei[1].y); if n=1 then begin writeln('.'); halt; end; for i:=2 to n do begin readln(a,b); map[a,b]:=true; end; end; procedure work; var i,j,k,p,g :longint; x,y :integer; bool :boolean; begin i:=1; j:=1; repeat p:=j; bool:=true; for g:=i to j do begin for k:=1 to 4 do begin x:=nei[g].x; y:=nei[g].y; case k of 1:inc(x); 4:dec(y); 3:dec(x); 2:inc(y); end; if (x>0) and (x<=10) and (y<=10) and (y>0) then if map[x,y] then begin case k of 1:write('R'); 4:write('B'); 3:write('L'); 2:write('T'); end; map[x,y]:=false; inc(p); bool:=false; nei[p].x:=x; nei[p].y:=y; end; end; if not((i=j) and bool) then writeln(',') else writeln('.'); end; i:=j+1; j:=p; until bool; end; begin into; work; end. 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. const dir :array [1..4,1..2] of shortint=((1,0),(0,1),(-1,0),(0,-1)); sign:array [1..4] of char=('R','T','L','B'); type rec=record x0,y0:integer; end; var xx,yy,i,n,j,x,y :integer; head,tail :integer; note1 :array [1..100] of rec; note2 :array [1..100] of string; a :array [1..100,1..100] of byte; f,m :byte; procedure init; var t1,t2 :string; st :string; begin for i:=1 to 100 do for j:=1 to 100 do a[i,j]:=0; readln(t1);readln(t2); if t2='.' then begin writeln(1);writeln(ord(t1[1])-48,' ',ord(t1[3])- 48);halt;end; for i:=1 to length(t2) do if ord(t2[i])>60 then begin f:=1;break;end else f:=2; if f=2 then begin n:=ord(t1[1])-48; note1[1].x0:=ord(t2[1])-48;note1[1].y0:=ord(t2[3])-48; for i:=2 to n do begin read(x,y);a[x,y]:=1;end; end else begin note1[1].x0:=ord(t1[1])-48;note1[1].y0:=ord(t1[3])-48; m:=0;st:=t2; repeat inc(m); if m=1 then note2[m]:=ST else begin readln(st);note2[m]:=st;end; until st='.'; end; head:=0;tail:=1; end; procedure work2; begin writeln(note1[1].x0,' ',note1[1].y0); repeat inc(head); for i:=1 to 4 do if a[note1[head].x0+dir[i,1],note1[head].y0+dir[i,2]]=1 then begin inc(tail); note1[tail].x0:=note1[head].x0+dir[i,1]; note1[tail].y0:=note1[head].y0+dir[i,2]; a[note1[tail].x0,note1[tail].y0]:=0; write(sign[i]) end; if head<>tail then writeln(','); until head>=tail; write('.'); end; procedure work1; var t:rec; begin writeln(m); repeat inc(head); for i:=1 to 4 do if pos(sign[i],note2[head])<>0 then begin inc(tail); note1[tail].x0:=note1[head].x0+dir[i,1]; note1[tail].y0:=note1[head].y0+dir[i,2]; end; until head=tail; for i:=1 to m do for j:=i+1 to m do if note1[i].x0>note1[j].x0 then begin t:=note1[i];note1[i]:=note1[j];note1[j]:=t;end; for i:=1 to m do for j:=i+1 to m do if note1[i].x0=note1[j].x0 then if note1[i].y0>note1[j].y0 then begin t:=note1[i];note1[i]:=note1[j];note1[j]:=t;end; for i:=1 to m do writeln(note1[i].x0,' ',note1[i].y0); end; begin init; if f=2 then work2 else work1; end. #include<iostream> using namespace std; int main() { char a,b,c[10]; int N,K=0; int line[400]; int open=0,close=0; int tx,ty,i=0,j=0; bool mat[20][20]={false}; int rec[20][20]; //////////////////////////////////////////////////////////// ////////////////////////////////////// for(i=0;i<10;i++) { for(j=0;j<10;j++) rec[i][j]=-1;
} cin>>a>>b>>c; if(c[0]>='1'&&c[0]<='9')goto dep1; else goto dep2; dep1: K=0; N=(int)a-48; tx=(int)b-48;ty=(int)c[0]-48; mat[tx][ty]=true; rec[tx][ty]=0; for(i=1;i<N;i++) { cin>>tx>>ty; mat[tx][ty]=true; }
tx=(int)b-48;ty=(int)c[0]-48; cout<<tx<<" "<<ty<<endl; while(1) { if(mat[tx+1][ty]==true&&rec[tx+1][ty]==-1) { cout<<"R"; line[close++]=tx+1; line[close++]=ty; rec[tx+1][ty]=0; } if(mat[tx][ty+1]==true&&rec[tx][ty+1]==-1) { cout<<"T"; line[close++]=tx; line[close++]=ty+1; rec[tx][ty+1]=0; } if(mat[tx-1][ty]==true&&rec[tx-1][ty]==-1) { cout<<"L"; line[close++]=tx-1; line[close++]=ty; rec[tx-1][ty]=0; } if(mat[tx][ty-1]==true&&rec[tx][ty-1]==-1) { cout<<"B"; line[close++]=tx; line[close++]=ty-1; rec[tx][ty-1]=0; } K++; if(K==N) { cout<<"."<<endl; break; } cout<<","<<endl; tx=line[open++]; ty=line[open++]; } goto end; dep2: tx=(int)a-48;ty=(int)b-48; mat[tx][ty]=true; i=0; while(1) { i=0; if(c[i]=='R') { mat[tx+1][ty]=true; i++; line[close++]=tx+1; line[close++]=ty; } if(c[i]=='T') { mat[tx][ty+1]=true; i++; line[close++]=tx; line[close++]=ty+1; } if(c[i]=='L') { mat[tx-1][ty]=true; line[close++]=tx-1; line[close++]=ty; i++; } if(c[i]=='B') { mat[tx][ty-1]=true; i++; line[close++]=tx; line[close++]=ty-1; } if(c[i]==',') { cin>>c; tx=line[open++]; ty=line[open++]; }
if(c[i]=='.') { K++; break; } else K++;
} cout<<K<<endl; for(i=0;i<20;i++) for(j=0;j<20;j++) if(mat[i][j]==true) cout<<i<<" "<<j<<endl; end: ; } #include <stdio.h> static int map[11][11]; int q[150][2]; int N,i,j; int x,y,a,b; int head,tail; int main() { scanf("%d",&N); a = 10,b = 10; for(i = 0;i < N;i++) { scanf("%d%d",&x,&y); map[x][y] = 1; if(x < a) { a = x,b = y; } else if(x == a && y < b) { a = x,b = y; } scanf("\n"); } printf("%d %d\n",a,b); for(head = 0,tail = head + 1,q[head][0] = a,q[head][1] = b,map[a][b] = 2;head < tail;head++) { x = q[head][0]; y = q[head][1]; if(map[x + 1][y] == 1) { map[x + 1][y] = 2; q[tail][0] = x + 1; q[tail++][1] = y; printf("R"); } if(map[x][y + 1] == 1) { map[x][y + 1] = 2; q[tail][0] = x; q[tail++][1] = y + 1; printf("T"); } if(map[x - 1][y] == 1) { map[x - 1][y] = 2; q[tail][0] = x - 1; q[tail++][1] = y; printf("L"); } if(map[x][y - 1] == 1) { map[x][y - 1] = 2; q[tail][0] = x; q[tail++][1] = y - 1; printf("B"); } map[x][y] = 3; if(tail - 1 == head) printf(".\n"); else printf(",\n"); } return 0; } program windy; var a:array[0..11,0..11] of 0..1; b:array[1..100,1..2] of 0..11; n,i,x,y,minx,miny,j:integer; procedure init; begin readln(n); for i:= 1 to n do begin readln(x,y); a[x,y]:=1; if x<minx then begin minx:=x; miny:=y end else if (x=minx) and (y<miny) then miny:=y; end; end; procedure work(i:integer); begin if i=n then writeln('.') else begin x:=b[i,1]; y:=b[i,2]; if a[x+1,y]=1 then begin write('R'); j:=j+1; a[x+1,y]:=0; b[j,1]:=x+1; b[j,2]:=y; end; if a[x,y+1]=1 then begin write('T'); j:=j+1; a[x,y+1]:=0; b[j,1]:=x; b[j,2]:=y+1; end; if a[x-1,y]=1 then begin write('L'); j:=j+1; a[x-1,y]:=0; b[j,1]:=x-1; b[j,2]:=y; end; if a[x,y-1]=1 then begin write('B'); j:=j+1; a[x,y-1]:=0; b[j,1]:=x; b[j,2]:=y-1; end; write(','); writeln; work(i+1) end end; begin minx:=20; miny:=20; fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); init; b[1,1]:=minx; b[1,2]:=miny; writeln(minx,' ',miny); j:=1; a[minx,miny]:=0; work(1); end. |
|