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. Memcached常用命令及使用说明

    一.存储命令 存储命令的格式: 1 2 <command name> <key> <flags> <exptime> <bytes> < ...

  2. hdu 4046 Panda 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ...

  3. hdu 3879 Base Station 最大权闭合图

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 A famous mobile communication company is plannin ...

  4. Leetcode#106 Construct Binary Tree from Inorder and Postorder Traversal

    原题地址 二叉树基本操作 [       ]O[              ] [       ][              ]O 代码: TreeNode *restore(vector<i ...

  5. Leetcode#135 Candy

    原题地址 遍历所有小孩的分数 1. 若小孩的分数递增,分给小孩的糖果依次+12. 若小孩的分数递减,分给小孩的糖果依次-13. 若小孩的分数相等,分给小孩的糖果设为1 当递减序列结束时,如果少分了糖果 ...

  6. shiro中unauthorizedUrl不起作用

    解决方法: 在shiro配置文件中添加(异常全路径做key,错误页面做value) <bean class="org.springframework.web.servlet.handl ...

  7. 在C语言中嵌入汇编语言

    TMS320C28x编译器允许在C程序中嵌入汇编指令,通过下面声明实现: asm(“assembler text”); 其中assembler text指汇编代码.asm指令一般用来处理C/C++语句 ...

  8. .NET设计模式(9):桥接模式(Bridge Pattern)(转)

    概述 在软件系统中,某些类型由于自身的逻辑,它具有两个或多个维度的变化,那么如何应对这种“多维度的变化”?如何利用面向对象的技术来使得该类型能够轻松的沿着多个方向进行变化,而又不引入额外的复杂度?这就 ...

  9. HDU4782 Beautiful Soup

    成都赛里的一道坑爹码力题,突然间脑抽想做一下弥补一下当时的遗憾.当时没做出这道题一是因为当时只剩大概45分钟,对于这样的具有各种条件的题无从下手,二则是因为当时估算着已经有银牌了,所以就不挣扎了.但是 ...

  10. Leetcode: strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...