比赛 20121016 评测结果 AAAAAAAAAA
题目名称 家族 最终得分 100
用户昵称 weichen 运行时间 0.006 s
代码语言 Pascal 内存使用 0.28 MiB
提交时间 2012-10-16 21:19:08
显示代码纯文本
program sas;
var
 a:array[0..202,0..202] of integer;
 f:array[0..202,0..202] of boolean;
 i,j,m,n,max:integer;
 s:string;
 dx:array[1..4] of -1..1;
 dy:array[1..4] of -1..1;

 procedure dfs(x,y:longint);
    var
      i,j:longint;
    begin
      for i:=1 to 4 do
         begin
           if f[x+dx[i],y+dy[i]] then
              begin

                f[x+dx[i],y+dy[i]]:=false;
                dfs(x+dx[i],y+dy[i]);
              end;
         end;
    end;

begin
 assign(input,'family.in');
 reset(input);
 assign(output,'family.out');
 rewrite(output);
 dx[1]:=-1;dx[2]:=0;dx[3]:=1;dx[4]:=0;
 dy[1]:=0;dy[2]:=1;dy[3]:=0;dy[4]:=-1;
 readln(n);    m:=0;
 for i:=1 to n do
   begin
     readln(s);
     if length(s)>m then m:=length(s);
     for j:=1 to length(s) do
       if (s[j]=' ')or(s[j]='*') then a[i,j]:=0
                                 else a[i,j]:=1;
   end;

 for i:=1 to n do
  for j:=1 to m do

   if a[i,j]<>0 then f[i,j]:=true;

 for i:=1 to n do
  for j:=1 to m do
   if (a[i,j]<>0)and(f[i,j]) then begin max:=max+1; dfs(i,j);   end;


 writeln(max);
 close(input);
 close(output);
end.