HDU - 1241 Oil Deposits 搜索dfs

3人阅读 评论(0) 收藏 举报
分类:

   遍历所有点,求出连通块的数量

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
//#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <string>
using namespace std;
#define ll long long
const int maxn = 10050;
char map[105][105];
int n, m, vis[105][105];
int dis[8][2] = {{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1},{1,0},{-1,0}};
void dfs(int i, int j) {
        vis[i][j] = 1;
        for (int k = 0; k < 8; k ++) {
                int xi = i + dis[k][0];
                int yi = j + dis[k][1];
                if (xi >= 0 && yi >= 0 && xi < n && yi < m && !vis[xi][yi] && map[xi][yi] == '@') {
                        dfs(xi, yi);
                }
        }
        return ;
}
int main()
{
        while (scanf("%d%d", &n, &m), n + m) {
                for (int i = 0; i < n; i ++) {
                        scanf("%s", map[i]);
                }
                int ans = 0;
                memset(vis, 0, sizeof(vis));
                for (int i = 0; i < n; i ++) {
                        for (int j = 0; j < m; j ++) {
                                if (!vis[i][j] && map[i][j] == '@') {
                                        ans ++;
                                        dfs(i, j);
                                }
                        }
                }
                printf("%d\n", ans);
        }
}



查看评论

SharePoint 搜索教程

以SharePoint 2016为环境,为大家介绍如何创建、使用SharePoint搜索服务,包括搜索SharePoint站点、非SharePoint站点、共享文件目录等,并学会配置和使用SharePoint搜索服务以及使用过程的注意事项等。 本次课程以SharePoint 2016为环境,同样适用于SharePoint 2013环境,部分配置适用于SharePoint 2010环境。
  • 2017年01月02日 20:49

杭电1241 HDU acm --Oil Deposits---DFS深度优先算法实现详解

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1241 又是经典搜索题!还是那句话,数据量小,要求简单,果断DFS! 这道题目跟以前的题目稍...
  • zhuihunmiling
  • zhuihunmiling
  • 2013-05-27 14:15:33
  • 2393

ACM-DFS之Oil Deposits——hdu1241

Oil Deposits Problem Description The GeoSurvComp geologic survey company is responsible for detecti...
  • lx417147512
  • lx417147512
  • 2014-02-25 12:47:46
  • 1939

hdu1241 Oil Deposits(dfs&&bfs)

这又是一个练习bfs和dfs的非常好的题目,找油井的个数,8个方向只要有,就算同一个,问有多少个下面是dfs的,没什么可说的#include #include using namespace st...
  • zcmartin2014214283
  • zcmartin2014214283
  • 2016-09-23 10:12:50
  • 522

hdu1241(Oil Deposits)

点击打开hdu1241 Problem Description The GeoSurvComp geologic survey company is responsible for detectin...
  • u011479875
  • u011479875
  • 2015-08-02 21:01:50
  • 949

Oil Deposits HDU杭电1241

Problem Description The GeoSurvComp geologic survey company is responsible for detecting undergroun...
  • yuzhiwei1995
  • yuzhiwei1995
  • 2015-08-03 19:52:32
  • 429

Oil Deposits(基础dfs)

Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T...
  • tree__water
  • tree__water
  • 2016-02-28 09:46:59
  • 536

ACM--DFS--poj 1562--Oil Deposits

poj地址:http://poj.org/problem?id=1562                                                         Oil ...
  • qq_26891045
  • qq_26891045
  • 2016-05-05 18:29:21
  • 1060

hdu Oil Deposits

算法:深搜 题意:让你判断有几个油库; Problem Description The GeoSurvComp geologic survey company is responsible fo...
  • wangxianse
  • wangxianse
  • 2015-12-09 20:25:50
  • 93

hdu1241 Oil Deposits (bfs水题)

Problem Description The GeoSurvComp geologic survey company is responsible for detecting undergroun...
  • zxy160
  • zxy160
  • 2017-05-27 20:17:12
  • 279
    个人资料
    持之以恒
    等级:
    访问量: 1万+
    积分: 500
    排名: 9万+
    最新评论