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 |
pascal发了8次才AC原来样例里的“Scenario”和空行都是有的哈 const dy:array[1..8] of -2..2=(-2,-2,-1,-1,1,1,2,2); dx:array[1..8] of -2..2=(-1,1,-2,2,-2,2,-1,1); var m,n,l,f:longint; t:boolean; b:array[-1..1001,-1..1001] of boolean; a:array[-1..1001] of longint; c:array[-1..1001] of char; procedure print; var i,j:longint; begin writeln('Scenario #',f,':'); for i:=1 to m*n do write(c[i],a[i]); writeln; writeln; t:=false; end; procedure search(x,y,z:longint); var i,j,k:longint; begin if not(t) then exit; if z>m*n then begin print;exit;end; for i:=1 to 8 do begin j:=x+dx[i];k:=y+dy[i]; if (j<=m)and(j>=1)and(k<=n)and(k>=1)and(b[j,k]) then begin b[j,k]:=false; a[z]:=j; c[z]:=chr(ord(k+64)); search(j,k,z+1); if not(t) then exit; a[z]:=0; b[j,k]:=true; c[z]:=' '; end; end; end; begin readln(l); for f:=1 to l do begin fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),true); fillchar(c,sizeof(c),' '); t:=true; readln(m,n); a[1]:=1; c[1]:='A'; b[1,1]:=false; search(1,1,2); if t then begin writeln('Scenario #',f,':'); writeln('impossible'); writeln; end; end; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator