标签:
题解:直接萌萌哒DFS秒之,经典的普及组难度基础题,水水哒
(Tip:38行的dfs(a1,a2)貌似只有这样写在本机才能对,提交也能A;很神奇的是如果直接写dfs(i,j)的话在本机就会出现带入的是(1,1)结果进去的是(2,2)QAQ,然后各种神奇跪OTL,更神奇的是这个在本机都跪成狗的程序居然submit之后也能A(QAQ),求神犇解释)
1 var 2 i,j,k,l,m,n,a1,a2:longint; 3 c1:char; 4 a:array[0..200,0..200] of longint; 5 procedure dfs(x,y:longint);inline; 6 begin 7 a[x,y]:=0; 8 if a[x-1,y-1]=1 then dfs(x-1,y-1); 9 if a[x,y-1]=1 then dfs(x,y-1); 10 if a[x+1,y-1]=1 then dfs(x+1,y-1); 11 if a[x-1,y+1]=1 then dfs(x-1,y+1); 12 if a[x,y+1]=1 then dfs(x,y+1); 13 if a[x+1,y+1]=1 then dfs(x+1,y+1); 14 if a[x-1,y]=1 then dfs(x-1,y); 15 if a[x+1,y]=1 then dfs(x+1,y); 16 end; 17 begin 18 readln(n,m); 19 fillchar(a,sizeof(a),0); 20 for i:=1 to n do 21 begin 22 for j:=1 to m do 23 begin 24 read(c1); 25 case c1 of 26 ‘W‘:a[i,j]:=1; 27 ‘.‘:a[i,j]:=0; 28 end; 29 end; 30 readln; 31 end; 32 l:=0; 33 for i:=1 to n do 34 for j:=1 to m do 35 if a[i,j]=1 then 36 begin 37 a1:=i;a2:=j; 38 inc(l);dfs(a1,a2); 39 end; 40 writeln(l); 41 readln; 42 end.
1751: [Usaco2005 qua]Lake Counting
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4391198.html