L - Oil Deposits

很清新的一道题,搜索里面最基础的题目,深搜广搜都可以.....不过还是喜欢深搜,写起来简单》。。

////////////////////////////////////////////////

#include<queue>
#include<stdio.h>
#include<string.h>
using namespace std;

const int maxn = 105;
const int oo = 0xfffffff;

int dir[8][2] = { {0,1},{0,-1},{1,0},{-1,0},
                  {1,-1},{1,1},{-1,1},{-1,-1}};
int M, N;
char G[maxn][maxn];

void DFS(int x, int y)
{
    if(x<0||x==M||y<0||y==N||G[x][y] != ‘@‘)
        return ;
    G[x][y] = ‘*‘;

for(int i=0; i<8; i++)
        DFS(x+dir[i][0], y+dir[i][1]);
}

int main()
{
    while(scanf("%d%d", &M, &N), M+N)
    {
        int i, j, ans=0;

for(i=0; i<M; i++)
            scanf("%s", G[i]);

for(i=0; i<M; i++)
        for(j=0; j<N; j++)
        {
            if(G[i][j] == ‘@‘)
            {
                ans++;
                DFS(i, j);
            }
        }

printf("%d\n", ans);
    }

return 0;

}

时间: 2024-11-08 07:09:03

L - Oil Deposits的相关文章

[kuangbin带你飞]专题一 简单搜索 - L - Oil Deposits

1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<queue> 6 using namespace std; 7 char g[105][105]; 8 int x, y, ans; 9 int dx[3]={1,0,-1}; 10 int dy[3]={1,0,-1}; 11 bool sscanf() 12

暑假集训Oil Deposits -----HDU1241

L - Oil Deposits Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposi

DFS(连通块) HDU 1241 Oil Deposits

题目传送门 1 /* 2 DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 3 */ 4 /************************************************ 5 Author :Running_Time 6 Created Time :2015-8-4 10:11:11 7 File Name :HDOJ_1241.cpp 8 ************************************************/ 9 10

hdoj 1241 Oil Deposits (dfs)

Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 17683    Accepted Submission(s): 10172 Problem Description The GeoSurvComp geologic survey company is responsible for detecting under

hdu 1241 Oil Deposits(DFS求连通块)

HDU 1241  Oil Deposits L -DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rec

UVa 572 - Oil Deposits【图DFS】

Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It

Oil Deposits hdu-1241 DFS

The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyze

HDU 1241 Oil Deposits(石油储藏)

p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo

HDU_1241 Oil Deposits(DFS深搜)

Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square pl