就是求图中有多少个水洼。对图进行dfs遍历,并把是水洼的地方全部标记。然后从下一个是水哇的地方再进行dfs。

 #include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int graph[][];
int sum;
bool vis[][];
int dx[] = {-, -, -, , , , , };
int dy[] = {-, , , -, , -, ,};
int row, col; bool check(int x, int y)
{
if( x >= && x < row && y >= && y < col)
return true;
return false;
} void dfs(int x, int y)
{
int ix, iy;
for(int i = ; i < ; i++)
{
ix = x + dx[i];
iy = y + dy[i];
if(!vis[ix][iy] && check(ix, iy) && graph[ix][iy] == )
{
vis[ix][iy] = true;
dfs(ix, iy);
}
}
}
int main()
{
//freopen("in.txt", "r", stdin);
cin >> row >> col;
getchar();
memset(vis, false, sizeof(vis)); char c;
for(int i = ; i < row; i ++)
{
for(int j = ; j < col; j++)
{
c = getchar();
graph[i][j] = (c == '.') ? : ;
}
getchar();
}
sum = ; for(int i = ; i < row; i ++)
{
for(int j = ; j < col; j++)
{
if(graph[i][j] == && vis[i][j] == false)
{
sum++;
vis[i][j] = true;
dfs(i, j);
}
}
} cout << sum << endl;
return ;
}

poj2386(简单dfs)的更多相关文章

  1. Red and Black(简单dfs)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. POJ 1979 Red and Black (简单dfs)

    题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...

  3. POJ1573(Robot Motion)--简单模拟+简单dfs

    题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...

  4. poj2386 Lake Counting(简单DFS)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...

  5. poj2386(简单的dfs/bfs)

    题目链接:http://poj.org/problem?id=2386 Description Due to recent rains, water has pooled in various pla ...

  6. POJ1979 Red and Black (简单DFS)

    POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  7. CF760 C. Pavel and barbecue 简单DFS

    LINK 题意:给出n个数,\(a_i\)代表下一步会移动到第\(a_i\)个位置,并继续进行操作,\(b_i\)1代表进行一次翻面操作,要求不管以哪个位置上开始,最后都能满足 1.到达过所有位置 2 ...

  8. uva 784 Maze Exploration(简单dfs)

    这道题看上去非常麻烦,什么迷宫啊.门之类的,事实上挺简单的,就是让把与 * 连通的都置为 # 包含 * , 直接dfs就能够了,只是我wa了好多次...最后居然是多读了一个换行.忘了加getchar( ...

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

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

随机推荐

  1. nyoj1007(euler 函数)

    euler(x)公式能计算小于等于x的并且和x互质的数的个数: 我们再看一下如何求小于等于n的和n互质的数的和, 我们用sum(n)表示: 若gcd(x, a)=1,则有gcd(x, x-a)=1: ...

  2. Sphinx的介绍和原理探索

    What/Sphinx是什么 定义 Sphinx是一个全文检索引擎. 特性 索引和性能优异 易于集成SQL和XML数据源,并可使用SphinxAPI.SphinxQL或者SphinxSE搜索接口 易于 ...

  3. 为 ASP.NET Web API 创建帮助页面(转载)

    转载地址:http://www.asp.net/web-api/overview/creating-web-apis/creating-api-help-pages 当创建web API 时,经常要创 ...

  4. 在ubuntu上搭建开发环境1---在windows7的基础上在安装ubuntu(双系统)

    转载:http://jingyan.baidu.com/article/60ccbceb18624464cab197ea.html 当需要频繁使用ubuntu时,vmware虚拟机下运行ubuntu, ...

  5. Oracle ASM

    一 Oracle ASM簡介 Oracle 10g推出的管理磁盤的新方式,用於取代LVM技術.主要用于RAC環境 二 Oracle ASM的配置安裝 1.安裝asm包 RedHat Linux5.x ...

  6. RFC(请求注解)--各种协议-标准

    转自:http://blog.sina.com.cn/s/blog_65d6476a0101cj8n.html RFC(Request For Comments)-意即“请求注解”,包含了关于Inte ...

  7. loj 1030概率dp

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 思路:一直以来对这种概率题都挺感冒的=.=......还是说一下思路吧,dp[i ...

  8. PE文件的执行顺序

    当一个PE文件被执行时,PE装载器首先检查DOS MZ header里的PE header的偏移量.如果找到,则直接跳转到PE header的位置. 当PE装载器跳转到PE header后,第二步要做 ...

  9. phpexecel 导入导出,格式

    1.日期时间合并到c中 =a1 &b1 或 =a1 + b1 这些都是运算符 2.此时c1的值是这条公式,而并不是公式运算的结果 复制c,粘贴到d,选择粘贴值 3.此时c是时间日期格式的,如需 ...

  10. loadrunner怎么将变量保存到参数中

    用这个lr_save_string 函数 char *b = "很简单";lr_save_string(b,"b"); lr_output_message(&q ...