就是求图中有多少个水洼。对图进行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. maven配置httpclient3.X jar包

    <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging& ...

  2. 利用 Rational ClearCase ClearMake 构建高性能的企业级构建环境

    转载地址:http://www.ibm.com/developerworks/cn/rational/r-cn-clearmakebuild/ 构建管理是 IBM® Rational® ClearCa ...

  3. Lattice 的 DDR IP核使用调试笔记之DDR 的 仿真

    —— 远航路上ing 整理于 博客园.转载请标明出处. 在上节建立完工程之后,要想明确DDR IP的使用细节,最好是做仿真.然后参考仿真来控制IP 核. 仿真的建立: 1.在IP核内的以下路径找到以下 ...

  4. MVC - 10.CodeFrist

    微软示例 1.(对新数据库使用 Code First):http://msdn.microsoft.com/zh-cn/data/jj193542 2.(连接和模型):http://msdn.micr ...

  5. 谈谈Delphi中的类和对象3---抽象类和它的实例

    四.抽象类和它的实例 Delphi中有一个类称为是抽象类,你不能天真的直接为它创建一个实例,如 var StrLst: TString; begin StrLst:= TString.Create; ...

  6. Task使用小结

    Task是.NET推出数据任务处理的工作类,Task的使用也被越来越多的人讲解,这里仅仅介绍Task的部分使用介绍: 1.Task简单创建 --无返回值 Task.Factory.StartNew(( ...

  7. lucene/solr 修改评分规则方法总结

    说明:由于solr底层使用的是lucene,因此修改solr打分机制归根结底还是依赖于lucene的打分机制,本文主要讨论lucene的打分机制. 本文说明lucene 常用的四种影响评分结果的方式. ...

  8. Install Docker on Mac OS X(转)

    Install Docker on Mac OS X You can install Docker using Boot2Docker to run docker commands at your c ...

  9. go sample - hello world

    入门级别的hello world package mainimport "fmt"func main() { fmt.Println("blibliblbibl!&quo ...

  10. 监听报错 TNS-00525: Insufficient privilege for operation 11gR2 + 连接报错ORA-12537: TNS:connection closed

    1.TNS-00525: Insufficient privilege for operation Started with pid= Listening on: (DESCRIPTION=(ADDR ...