就是求图中有多少个水洼。对图进行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. 用spring+hibernate+struts 项目记录以及常用的用法进等

    一.hibernate1. -----BaseDao------ // 容器注入 private SessionFactory sessionFactory; public void setSessi ...

  2. MVC公开课 – 2.查询,删除 (2013-3-15广州传智MVC公开课)

    查询 /Controller/HomeController.cs /// <summary> /// 查询 文章 列表 /// </summary> /// <retur ...

  3. 11.外观模式(Facade Pattern)

    using System; namespace ConsoleApplication4 { class Program { /// <summary> /// 不使用外观模式的情况 /// ...

  4. 七牛---以一个七牛上传的实例小结下AJAX跨域【转】

    http://blog.csdn.net/netdxy/article/details/50699842 使用七牛过程中,很多用户或多或少遇到跨域的问题,这篇文章主要介绍下跨域的概念来看什么情况下会出 ...

  5. Shell编程基础教程2--变量和运算符

    2.变量和运算符 2.1.变量的类型 本地变量:环境变量:变量替换(显示变量):位置变量:标准变量:特殊变量: 2.2.本地变量 本地变量在用户现在的shell生命周期的脚本中使用 在命令行, LOC ...

  6. 百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET 2015-01-12 11:18 346人阅读 评论(0) 收藏

    在百度编辑器示例代码基础上进行了修改,封装成类库,只需简单配置即可使用. 完整demo下载 版权声明:本文为博主原创文章,未经博主允许不得转载.

  7. go-martini 简单分析之一

    env.go 环境变量 const ( Dev string = "development" Prod string = "production" Test s ...

  8. Oracle性能优化

    (1) 选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE的解析器按照 从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最 ...

  9. visio 交叉线 不出现拱形怎么办?

  10. 解决全局变量共享---C语言的extern关键字用法

    在调试程序时,有一个参数需要在多个函数之间传递,因为是作为调试参数,不想将参数引入到函数中. 很自然的想到使用全局变量来表示这个公共参数,工程代码的结构如下: main.c test.c test.h ...