usaco numgrid 2008.9.29

来源:互联网 发布:阿里云如何域名解析 编辑:程序博客网 时间:2024/06/10 14:28

usaco numgrid 2008.9.29

虽然说是六位数,但是,因为题中说道,会有000011 etc的形式,所以哈希就要从0 –999999而不是100000-999999,这点wa了

{

ID:

PROG:numgrid

LANG:PASCAL

}

program p_numgrid;const fin='numgrid.in';fout='numgrid.out';      p:array[1..4,1..2]of longint=((-1,0),(1,0),(0,-1),(0,1));var a:array[1..5,1..5]of longint;    x:array[0..999999]of boolean;    ans,s:longint;    f1,f2:text;procedure init;var i,j:longint;begin  assign(f1,fin);reset(f1);  assign(f2,fout);rewrite(f2);  for i:=1 to 5 do     for j:=1 to 5 do       read(f1,a[i,j]);  fillchar(x,sizeof(x),true);  ans:=0;end;procedure put;begin  if x[s] then begin inc(ans);x[s]:=false;end;end;procedure deal(x1,x2,m:longint);var y1,y2,i:longint;begin  if m=6 then begin put;exit;end;  for i:=1 to 4 do    begin      y1:=x1+p[i,1];      y2:=x2+p[i,2];      if (y1>0) and (y1<6) and (y2>0) and (y2<6) then         begin          s:=s*10+a[y1,y2];          deal(y1,y2,m+1);          s:=s div 10;         end;    end;end;procedure doit;var i,j:longint;begin  for i:=1 to 5 do    for j:=1 to 5 do      begin s:=a[i,j];            deal(i,j,1);      end;end;begin  init;  doit;  writeln(f2,ans);close(f1);close(f2);end.


0 0
原创粉丝点击