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 |
热烈庆祝我一次AC 0ms无压力,附代码pascal版!!!看见讨论里头的同志那么惨,我觉得我太幸运了,还是0ms!!!瞧这人品^_^ type node=record a,b:longint; end; var a:array[-5..100,-5..100] of longint; f:array[1..800] of node; i,j,k,n,L,w,p,left:longint; function dfs(x,y:longint):boolean; procedure insert; begin inc(p); f[p].a:=x; f[p].b:=y; end; begin a[x,y]:=1; dec(left); if left=0 then begin insert; exit(true); end; {1}if a[x-1,y-2]=0 then if dfs(x-1,y-2) then begin insert; exit(true); end; {2}if a[x+1,y-2]=0 then if dfs(x+1,y-2) then begin insert; exit(true); end; {3}if a[x-2,y-1]=0 then if dfs(x-2,y-1) then begin insert; exit(true); end; {4}if a[x+2,y-1]=0 then if dfs(x+2,y-1) then begin insert; exit(true); end; {5}if a[x-2,y+1]=0 then if dfs(x-2,y+1) then begin insert; exit(true); end; {6}if a[x+2,y+1]=0 then if dfs(x+2,y+1) then begin insert; exit(true); end; {7}if a[x-1,y+2]=0 then if dfs(x-1,y+2) then begin insert; exit(true); end; {8}if a[x+1,y+2]=0 then if dfs(x+1,y+2) then begin insert; exit(true); end; inc(left); a[x,y]:=0; exit(false); end; procedure print; begin while p>0 do begin write(chr(f[p].b+64),f[p].a); dec(p); end; writeln; end; begin readln(n); for k:=1 to n do begin fillchar(a,sizeof(a),$FF); p:=0; readln(L,w); left:=L*w; for i:=1 to L do for j:=1 to w do a[i,j]:=0; writeln('Scenario #',k,':'); if dfs(1,1) then print else writeln('impossible'); if k<>n then writeln; end; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator