POJ2386 Lake Counting——Floodfill
来源:互联网 发布:税务局开票软件下载 编辑:程序博客网 时间:2024/06/12 23:51
标准的floodfill即可,在floodfill的过程中累加ans.
CODE
Program POJ2386;Const maxn=105;ddx:Array[1..8]of Integer=(0,0,1,1,1,-1,-1,-1);ddy:Array[1..8]of Integer=(-1,1,0,1,-1,0,-1,1);Typerec=recordx,y:Longint;end;Varmap:Array[0..maxn,0..maxn]of Char;v:Array[0..maxn,0..maxn]of Boolean;ch:Char;i,j,k,m,n,ans:Longint;seq:Array[0..maxn*maxn]of rec;Procedure Floodfill(x,y:Longint);var h,t,i,j,a,b:Longint;beginh:=0;t:=1;seq[t].x:=x;seq[t].y:=y;while h<t do begininc(h);a:=seq[h].x;b:=seq[h].y;for i:=1 to 8 doif (a+ddx[i]<=n)and(a+ddx[i]>0)and(b+ddy[i]<=m)and(b+ddy[i]>0)thenif (map[a+ddx[i],b+ddy[i]]='W')and(not v[a+ddx[i],b+ddy[i]]) then beginv[a+ddx[i],b+ddy[i]]:=true;inc(t);seq[t].x:=a+ddx[i];seq[t].y:=b+ddy[i];end;end;end;BEGINreadln(n,m);for i:=1 to n do beginfor j:=1 to m do read(map[i,j]);readln;end;ans:=0;fillchar(v,sizeof(v),0);for i:=1 to n do for j:=1 to m doif (not v[i,j])and(map[i,j]='W') then beginFloodfill(i,j);inc(ans);end;writeln(ans);END.
- POJ2386 Lake Counting——Floodfill
- poj2386——Lake Counting
- POJ2386——Lake Counting
- poj2386——Lake Counting(搜索)
- POJ2386 Lake Counting
- POJ2386:Lake Counting(DFS)
- poj2386 Lake Counting DFS
- poj2386 Lake Counting
- poj2386 Lake Counting
- POJ2386 Lake Counting(DFS)
- poj2386 Lake Counting
- POJ2386 Lake Counting 【DFS】
- Lake Counting--poj2386
- poj2386 Lake Counting
- POJ2386 Lake Counting
- POJ2386-Lake Counting
- POJ2386 Lake Counting
- POJ2386 Lake Counting
- 【转】 使用Google搜索全球网络摄像头
- Flash/Photoshop/AE/图形图像资源下载地址
- struts2手动防止数据重复提交,使用struts标签取session中的值
- PHP/MySQL资源下载地址
- Equals() 与 == operator 的区别
- POJ2386 Lake Counting——Floodfill
- Heap使用及GC_EXTERNAL_ALLOC含义
- JQuery/AjaX/Javascript/DIV+CSS资源下载地址
- 使用CentOS 6.0 VPN 客户端连接H3C路由器
- POJ2387 Til the Cows Come Home——Heap+dijkstra
- vs2008发布失败完美解决方案
- 026电话区号之争!
- AIX6.1 xlc8.0不能使用的问题
- C++数组反转模板函数