Oil Deposits HDU 1241
InputThe input file 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.
OutputFor each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they 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
#include <bits/stdc++.h>
using namespace std;
#define M 102 char map1[M][M];
int vis[M][M];
int m,n,sum;
int dir[8][2] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; void dfs(int x, int y){
for(int i = 0; i < 8; i++)
{
int dx = x + dir[i][0];
int dy = y + dir[i][1];
if(dx >= 0 && dy >= 0 && dx < m && dy < n && map1[dx][dy] == '@' && !vis[dx][dy]){
vis[dx][dy] = 1;
dfs(dx,dy);
}
}
return;
} int main(){
while(cin>>m>>n && m && n){
memset(vis,0,sizeof(vis));
sum = 0;
getchar();
for(int i = 0; i < m; i++)
scanf("%s",map1[i]);
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
if(map1[i][j] == '@' && !vis[i][j]){
sum++;dfs(i,j);
}
cout<<sum<<endl;
}
return 0;
}
Oil Deposits HDU 1241的更多相关文章
- Oil Deposits HDU - 1241 (dfs)
Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...
- (深搜)Oil Deposits -- hdu -- 1241
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- kuangbin专题 专题一 简单搜索 Oil Deposits HDU - 1241
题目链接:https://vjudge.net/problem/HDU-1241 题意:问有几个油田,一个油田由相邻的‘@’,组成. 思路:bfs,dfs都可以,只需要遍历地图,遇到‘@’,跑一遍搜索 ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
- HDU 1241 Oil Deposits(石油储藏)
HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Probl ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- DFS(连通块) HDU 1241 Oil Deposits
题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
随机推荐
- [skill][https][ssl/tls] HTTPS相关知识汇总
结论前置: A 身份验证 证书, 服务器证书 B 密钥协商 RSA DHE / ECDHE PSK C 加密通信 加密通信采用对称加密,使用B阶段协商出来的密钥. B 阶段如果使用 RSA 协 ...
- ORACLE DIRECTORY目录管理步骤
ORACLE DIRECTORY目录管理步骤 ORACLE的 DIRECTORY在数据库中是个目录的路径,需要在操作系统中有相应的目录与之对应:ORACLE目录的作用就是让ORACLE数据库和操作系统 ...
- 【pyqtgraph绘图】案例-动态的正余弦波形图
先看一个简单的小例子: 完整代码: import numpy as np import pyqtgraph as pg import sys from PyQt5.QtWidgets import Q ...
- Redis分布式锁服务(转)
原文:http://www.cnblogs.com/mushroom/p/4752499.html 概述 在多线程环境下,通常会使用锁来保证有且只有一个线程来操作共享资源.比如: object obj ...
- No converter found for return value of type
springMVC请求接口的时候报500 No converter found for return value of type 原因:这是因为springmvc默认是没有对象转换成json的转换器 ...
- 【数据库】left join(左关联)、right join(右关联)、inner join(自关联)的区别
left join(左关联).right join(右关联).inner join(自关联)的区别 用一张图说明三者的区别: 总结: left join(左联接) 返回包括左表中的所有记录和右表中关联 ...
- shiro 身份授权+权限认证
https://www.cnblogs.com/cmyxn/p/5825099.html
- 所使用的“System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35”版本高于所引用的程序集“System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”的版本
System.Web.Mvc.dll引用是感叹号. 解决方法:新建mv3应用程序,右键选择System.Web.Mvc.dll 查看所引用的路径. 在旧程序中重新引用即可.C:\Program Fil ...
- 如何把Composer镜像迁移到Laravel China 维护的镜像?
今天在更新Laravel-admin:1.6.0提示没有对应的包,后面才发现需要使用官方或者 Laravel-China 的 composer 镜像,phpcomposer 镜像已经停止维护了.怎么从 ...
- Windows系统重装工具 WinToHDD Enterprise v2.8 企业破解版
WinToHDD 是一款实用的 Windows 系统硬盘安装工具,有点类似于NT6 HDD Installer,它能不依靠光驱和U盘,让你直接通过本机硬盘来新装.重装和克隆 Windows 系统,支持 ...