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. Codeforce 977E Cyclic Components

    dfs判断图的连通块数量~ #include<cstdio> #include<algorithm> #include<vector> #include<cs ...

  2. 新建文件的UID和GID

    默认情况下:新建文件的用户ID为操作当前文件进程的有效用户ID(参考以前文章),新建文件的组ID为操作当前文件的进程的有效组ID 特殊情况:当当前新建文件的目录的SET-GID位被设置时,那么新建文件 ...

  3. Docker for YApi--一键部署YApi

    获取YApi镜像$ docker pull mrjin/yapi:latest 注意:本仓库目前只支持安装,暂不支持升级,请知晓.如需升级请备份mongoDB内的数据. docker-compose ...

  4. Ubuntu 12.10 安装vim出错

    在Ubuntu 12.10中安装vim时出现了如下提示: 正在读取软件包列表... 完成正在分析软件包的依赖关系树 正在读取状态信息... 完成 有一些软件包无法被安装.如果您用的是 unstable ...

  5. vue 的模拟数据

    首先分析需要什么数据,然后在build下 找到dev-server.js 在里面有一个var 项目名 = express() 在后面添加我们自己需要模拟的数据路由 // 自己添加路由 读取数据 sta ...

  6. linux动态监控dstat&&glances&&psutil&&bottle

    安装dstat yum install dstat 安装glances yum install python-devel pip install glances 如果我们安装了 Bottle 这个 w ...

  7. 十二 INPUT逻辑视图的配置,回显错误信息

    Action接口中提供了五个逻辑视图的名称 SUCCESS ERROR LOGIN INPUT:input在某些拦截器会使用 NONE 配置逻辑视图:struts_demo2.xml,配置后出现错误信 ...

  8. java_3:JVM、JRE、JDK区别和联系

    首先 三者之间存在包含关系JVM + 核心类库 = JREJRE + java开发工具(javac.exe/jar.exe) = JDK 什么是JVM? 我们知道Java语言有一个独特的优点就是可以跨 ...

  9. kafka的搭建,命令

    a)kafka搭建 1.解压 2.修改配置/software/kafka_2.11-0.11.0.3/config/server.properties broker.id=0 log.dirs=/va ...

  10. 「JOI2019 Final」解题报告

    传送门 「JOI2019 Final」勇者比太郎 看懂题就很简单了,后缀和随便维护一下就好了,别用树状数组强加一个\(\log\)就行. 「JOI2019 Final」画展 显然可以先把所有的画框按大 ...