Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

热烈庆祝我一次AC 0ms无压力,附代码pascal版!!!

Posted by heshibidahe at 2012-03-24 16:17:00 on Problem 2488
看见讨论里头的同志那么惨,我觉得我太幸运了,还是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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator