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 analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.

Input

The input contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.

Output

are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.

Sample Input

1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0

Sample Output

0
1
2
2 分析:板子题,求连通块个数,用DFS+种子填充法即可,直接给出代码:
const int maxm = ;

int vis[maxm][maxm], n, m;
string G[maxm]; bool inside(int x, int y) {
return x >= && x < n && y >= && y < m;
} void dfs(int x,int y, int id) {
if(vis[x][y])
return;
vis[x][y] = id;
for(int i = -; i < ; ++i) {
for (int j = -; j < ; ++j) {
if(i || j) {
int nx = x + i, ny = y + j;
if(inside(nx,ny) && G[nx][ny] == '@' && !vis[nx][ny])
dfs(nx, ny, id);
}
} }
} int main() {
while(scanf("%d%d",&n,&m) && n+m) {
getchar();
memset(vis, , sizeof(vis));
for(int i = ; i < n; ++i)
cin >> G[i];
int sum = ;
for(int i = ; i < n; ++i) {
for(int j = ; j < m; ++j) {
if(G[i][j] == '@' && !vis[i][j])
dfs(i, j, ++sum);
}
}
printf("%d\n",sum);
}
}

Day2-D-Oil Deposits-POJ-1562的更多相关文章

  1. POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)

    题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...

  2. POJ 1562 Oil Deposits (并查集 OR DFS求联通块)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14628   Accepted: 7972 Des ...

  3. [POJ] 1562 Oil Deposits (DFS)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16655   Accepted: 8917 Des ...

  4. (简单) POJ 1562 Oil Deposits,BFS。

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  5. HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题

    Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil de ...

  6. POJ 1562:Oil Deposits

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14462   Accepted: 7875 Des ...

  7. Oil Deposits(poj 1526 DFS入门题)

    http://poj.org/problem?id=1562                                                                       ...

  8. HDU 1562 Oil Deposits

    题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...

  9. Oil Deposits

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  10. Oil Deposits(dfs)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

随机推荐

  1. mark mark mark

    编译并使用静态lib---->>>>转自:Walkthrough: Creating and Using a Static Library (C++) 跟踪内存分配:http: ...

  2. stm32CubeMx lwip + freeRTOS

    MCU: STM32F429IGT6 工具:STM32CubeMx  版本号 5.0.0 Keil uVersion5 目的:使用LWIP 实现简单的网络连通 一  简介 LWIP(Light Wei ...

  3. PHP实现链式操作的三种方法详解

    这篇文章主要介绍了PHP实现链式操作的三种方法,结合实例形式分析了php链式操作的相关实现技巧与使用注意事项,需要的朋友可以参考下 本文实例讲述了PHP实现链式操作的三种方法.分享给大家供大家参考,具 ...

  4. 【网摘】监控 div 的内容变化

    数据是动态加载而来,而当无数据时,提示一下暂无数据.而数据是可以动态在当前页面即时添加的,故在无数据时所做提示,需要隐藏,所以找了这个方法.成功在动态添加数据后,暂无数据的提示没有了. if($(&q ...

  5. 五年C语言程序员,是深耕技术还是走管理?

    从进入程序员行列开始(2013年6月),到现在为止(2019年2月),已经有五年半了.    一路波折,已经从无知菜鸟走到了意识觉醒的老鸟了.    薪资变化情况如下: 2013年:2000元/月 ( ...

  6. 语言国际化:中文ASC码互转

    https://javawind.net/tools/native2ascii.jsp 1.首先找到了上面的链接,也就是下图,输入中文就可立即得出ASCII码 2.看到上图第一条,找到了JDK/bin ...

  7. TCP通讯代码

    服务端代码: import socket server_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) # 使用固定端口 server_ ...

  8. QT无法读入txt文件内容

    用vs写QT无法利用相对路径读入txt文件,应将此文件加入到资源文件中.

  9. nginx 加工上游服务器返回的内容,并返回给客户端

    禁用上游响应头部功能 Syntax: proxy_ignore_headers field ...; Default: — Context: http, server, location 功能介绍:某 ...

  10. pycharm自定义代码段

    PyCharm使用技巧:Live Templates(快速输入自定义代码片段):链接