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. Leetcode#123 Best Time to Buy and Sell Stock III

    原题地址 最直观的想法就是划分成两个子问题,每个子问题变成了:求在某个范围内交易一次的最大利润 在只能交易一次的情况下,如何求一段时间内的最大利润?其实就是找股价最低的一天买进,然后在股价最高的一天卖 ...

  2. 2011 Asia Fuzhou Regional Contest

    Xiangqi http://acm.hdu.edu.cn/showproblem.php?pid=4121 模拟,用高内聚低耦合的思想来写模拟题还是很好的,提高了函数的可重用性,程序的可读性,正确性 ...

  3. 用npm安装express后express命令找不到

    Windows 平台加了 npm install -g express 也不行AppData\Roaming\npm 下面没有 express.bat 解决办法: sudo npm install - ...

  4. [nowCoder] 二进制中1的个数

    题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示.     class Solution { public: int NumberOf1(int n) { ; while(n) ...

  5. Topcoder 多校T-shirt场

    盗用名字:C题题目都没看懂, B:You are given a long long n. Return the largest divisor of n that is a perfect squa ...

  6. 使用Rails 4.2+ 测试异步邮件系统

    [导读]异步测试总是一个很大的问题,邮件发送测试更是让很多开发同学不知道从哪里入手.在新版的Rails里,这类测试在很大程度上被简化了. 以下为译文 在编写需要发送邮件的应用时,控制器是绝不能被阻塞的 ...

  7. C# 前台线程与后台线程的区别和联系

    c#前台线程与后台线程的区别和联系http://www.189works.com/article-13702-1.html 如何取消后台线程的执行http://www.cnblogs.com/shan ...

  8. Linux之select系统调用_1

    SYNOPSIS /* According to POSIX.1-2001 */ #include <sys/select.h> /* According to earlier stand ...

  9. 使用var声明的变量 和 直接赋值并未声明的变量的区别

    在看JS高级程序设计时忽然想到这个问题,众所周知,直接赋值一个变量而为声明,会产生一个全局变量(或者说是全局对象的属性),但用var声明的变量 和 直接赋值而并未声明的变量 都有哪些区别呢,这是我在百 ...

  10. 自己的gitignore文件

    *.bak*.txt*.vm.gitignore#svn.svn/# built application files*.apk*.ap_ # files for the dex VM*.dex # J ...