就是求图中有多少个水洼。对图进行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. [网络流24题] 太空飞行计划(cogs 727)

    [问题描述] W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,-,Em},和进行这些实验需要使用的全部仪 ...

  2. java链式编程设计

    一般情况下,对一个类的实例和操作,是采用这种方法进行的: Channel channel = new Channel(); channel.queueDeclare(QUEUE_NAME, true, ...

  3. alias命令(使用命令别名)

    通过alias命令可以给一些命令定义别名,如,将长的难记住的命令起一个容易记住的别名,提高工作效率 alias -p 查看已有的别名列表 命名别名格式: alias 新命令名='原命令名 -参数/选项 ...

  4. NYOJ题目98成绩转换

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsQAAAJhCAIAAADJ5jGJAAAgAElEQVR4nO3dq3LkSPg36O8mzH0hxn ...

  5. acpi参考网站

    1.acpi官网: http://www.acpi.info/

  6. 分享一个最近研究的手机QQ3.0的协议(版本1.4)

    最近闲来有事, 分析了一个非常低端(非常低端的意思是说你不应该对她是否能取代你现有的QQ客户端作任何可能的奢望,她只是一个实验性的东西)的手机QQ的协议, 是手机QQ3.0,      所用到的TCP ...

  7. HYSBZ 2440 完全平方数(莫比乌斯反演)

    链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2440 若i为质数,n为i*i的倍数,则称n为含平方因子数. 求1~n的无平方因子数. F(x) ...

  8. 11g SQL Monitor

    1,首先确认两个参数的值 SQL> show parameter statistics_level NAME                     TYPE     VALUE ------- ...

  9. ASP.Net MVC开发基础学习笔记(4):校验、AJAX与过滤器

    一.校验 — 表单不是你想提想提就能提 1.1 DataAnnotations(数据注解) 位于 System.ComponentModel.DataAnnotations 命名空间中的特性指定对数据 ...

  10. 从客户端(CourseIssueContent="<P>财务审计师岗位认证招生简章<BR>...")中检测到有潜在危险的 Request.Form 值。

    说明: 请求验证过程检测到有潜在危险的客户端输入值,对请求的处理已经中止.该值可能指示危及应用程序安全的尝试,如跨站点的脚本攻击.通过在 Page 指令或 配置节中设置 validateRequest ...