比赛 20140714下午练习 评测结果 C
题目名称 城堡 最终得分 0
用户昵称 (⊙o⊙)… 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2014-07-14 15:07:36
显示代码纯文本
program xx;
var
a:array[1..100,1..100] of integer;
n,m:integer;
const
 s:array[1..4,1..2]of shortint=((0,-1),(-1,0),(0,1),(1,0));
 t:array[1..4]of shortint=(1,2,4,8);
var
 r:array[1..1000,1..2]of integer;
 a:array[0..51,0..51]of integer;
 p:array[0..51,0..51]of integer;
 q:array[0..51,0..51]of integer;
 c:array[0..51,0..51]of boolean;
 m,n,i,j,k,max,min,l,x,x1,y1,dir,num:integer;
procedure can(x,y:integer);
 var
  i,j:integer;
 begin
  r[l,1]:=x;r[l,2]:=y;
  c[x,y]:=false;
  for i:=1 to 4 do
   begin
    if (a[x,y]and(t[i])=0)and (c[x+s[i,1],y+s[i,2]])then begin l:=l+1;can(x+s[i,1],y+s[i,2]);end;
   end;
 end;
 begin
 assign(input,'castle.in');
 assign(output,'castle.out');
 reset(input);
 rewrite(output);
 min:=10000;
 read(m,n);
 for i:=1 to n do
  for j:=1 to m do
   read(a[i,j]);
 fillchar(c,sizeof(c),true);
 for i:=0 to 50 do
  begin
   c[0,i]:=false;
   c[i,0]:=false;
  end;
 for i:=1 to n do
  for j:=1 to m do
   if (c[i,j]) then
    begin
     l:=1;
     k:=k+1;
     can(i,j);
     if l>max then max:=l;
     if min>l then min:=l;
     for x:=1 to l do
      begin
       q[r[x,1],r[x,2]]:=k;
       p[r[x,1],r[x,2]]:=l;
      end;
    end;
 fillchar(c,sizeof(c),true);
 for i:=0 to 50 do
  begin
   c[0,i]:=false;
   c[i,0]:=false;
   c[n+1,i]:=false;
   c[i,m+1]:=false;
  end;

 for j:=1 to m do
  for i:=n downto 1 do
   for x:=2 to 3 do
    if (q[i,j]<>q[i+s[x,1],j+s[x,2]])and(c[i+s[x,1],j+s[x,2]]) then
    if num<p[i,j]+p[i+s[x,1],j+s[x,2]]then
     begin
      num:=p[i,j]+p[i+s[x,1],j+s[x,2]];
      x1:=i;
      y1:=j;
      dir:=x
     end;
 writeln(k);
 writeln(max);
 writeln(num);
 write(x1,' ',y1);
 case dir of
 1:write('W');
 2:write('N');
 3:write('E');
 4:write('S');
 end;
 close(input);
 close(output);
end.