http://poj.org/problem?id=2386

http://acm.hdu.edu.cn/showproblem.php?pid=1241

求有多少个连通子图。复杂度都是O(n*m)。

 #include <cstdio>

 char filed[][];
int n,m;
void dfs(int x,int y)
{
for(int i=-;i<=;i++)
for(int j=-;j<=;j++) //循环遍历8个方向
{
int xx=x+i,yy=y+j;
if(xx>=&&xx<n&&yy>=&&yy<m&&filed[xx][yy]=='W')
{
filed[xx][yy]='.';
dfs(xx,yy);
}
}
return;
} int main()
{
//freopen("a.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
getchar();
int count=;
for(int i=;i<n;i++) scanf("%s",filed[i]);
for(int i=;i<n;i++)
for(int j=;j<m;j++)
if(filed[i][j]=='W')
{
dfs(i,j);
count++;
}
printf("%d\n",count);
}
return ;
}

poj - 2386 Lake Counting && hdoj -1241Oil Deposits (简单dfs)的更多相关文章

  1. poj 2386:Lake Counting(简单DFS深搜)

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18201   Accepted: 9192 De ...

  2. POJ 2386 Lake Counting(深搜)

    Lake Counting Time Limit: 1000MS     Memory Limit: 65536K Total Submissions: 17917     Accepted: 906 ...

  3. POJ 2386 Lake Counting

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28966   Accepted: 14505 D ...

  4. [POJ 2386] Lake Counting(DFS)

    Lake Counting Description Due to recent rains, water has pooled in various places in Farmer John's f ...

  5. POJ 2386 Lake Counting(搜索联通块)

    Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48370 Accepted: 23775 Descr ...

  6. POJ:2386 Lake Counting(dfs)

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40370   Accepted: 20015 D ...

  7. POJ 2386 Lake Counting 八方向棋盘搜索

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 53301   Accepted: 26062 D ...

  8. POJ 2386 Lake Counting (简单深搜)

    Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...

  9. POJ 2386 Lake Counting DFS水水

    http://poj.org/problem?id=2386 题目大意: 有一个大小为N*M的园子,雨后积起了水.八连通的积水被认为是连接在一起的.请求出院子里共有多少水洼? 思路: 水题~直接DFS ...

随机推荐

  1. 06.Hibernate实体类生命周期

        前言:Session接口是Hibernate向应用程序提供的操作数据库的主要接口,它提供了基本的增删查改方法,而且Session具有一个缓存它是Hibernate的一级缓存.站在持久化层的角度 ...

  2. shell编程之分隔符

    1 #!/bin/bash 2 line="root:x:0:0:root:/root:bin/bash" 3 oldIFS=$IFS 4 IFS=":" 5 ...

  3. winform 记录全局异常捕获

    这篇文章主要是备用 记录winform程序捕获全局异常. /// <summary> /// 应用程序的主入口点. /// </summary> public static A ...

  4. [工作积累] bitfield

    ISO/IEC 14882:2003: 9.6 Bit-fields [class.bit] A member-declarator of the form identifieropt : const ...

  5. Linux 的多线程编程的高效开发经验

    http://www.ibm.com/developerworks/cn/linux/l-cn-mthreadps/ 背景 Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多 ...

  6. WinHex分析PE格式(1)

    最近在一直努力学习破解,但是发现我的基础太差了,就想学习一下PE结构.可是PE结构里的结构关系太复杂,看这老罗的WiN32汇编最后一章 翻两页又合上了..把自己的信心都搞没了.感觉自己的理解能力不行, ...

  7. sql server 存储过程,事务

    1.存储过程,事务 CREATE PROCEDURE Proc_ceshi @id int, ), @returnval int output AS BEGIN SET NOCOUNT ON; Set ...

  8. 2014多校第十场1002 || HDU 4972 A simple dynamic programming problem

    题目链接 题意 : 每次无论哪个队投进一个篮球,就记下现在两队比分的差值,问你最后的结果有多少种情况. 思路 : 该题实在是不好理解,最后的结果有多少种情况就是说不管中间过程怎么来的,只要最后结果不一 ...

  9. hdu 4753 Fishhead’s Little Game 博弈论+记忆化搜索

    思路:状态最多有2^12,采用记忆化搜索!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm& ...

  10. VISO下载地址

    http://pan.baidu.com/share/home?uk=4011207371#category/type=0