hdoj 1241 Oil Deposits (DFS)
来源:互联网 发布:mac同时登陆多个qq 编辑:程序博客网 时间:2024/06/11 23:09
水。。
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10748 Accepted Submission(s): 6253
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 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 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.
Output
For 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
0122
Source
Mid-Central USA 1997
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int N = 110;char mp[N][N];int vis[N][N];int dir[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};int n, m;int cnt;void dfs(int x, int y){ vis[x][y] = 1; for(int i = 0; i < 8; i++){ int xx = x + dir[i][0], yy = y + dir[i][1]; if(mp[xx][yy] == '@' && !vis[xx][yy]){ vis[xx][yy] = 1; dfs(xx, yy); } }}int main(){ while(scanf("%d%d", &n, &m) != EOF, n || m){ memset(mp, '\0', sizeof(mp)); for(int i = 1; i <= n; i++) scanf("%s", mp[i] + 1); cnt = 0; memset(vis, 0, sizeof(vis)); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(mp[i][j] == '@' && !vis[i][j]){ cnt++; dfs(i, j); } } } printf("%d\n", cnt); } return 0;}
0 0
- HDOJ--1241--Oil Deposits【DFS】
- hdoj 1241 Oil Deposits (DFS)
- hdoj 1241 Oil Deposits【DFS】
- HDOJ 1241 Oil Deposits(dfs)
- HDOJ 1241 Oil Deposits (DFS)
- HDOJ 1241 Oil Deposits【DFS】
- hdoj problem 1241 Oil Deposits(深搜 DFS)
- HDOJ 1241 Oil Deposits (DFS)
- HDOJ/HDU 1241 Oil Deposits(经典DFS)
- HDOJ 1241 Oil Deposits(DFS)
- HDOJ(HDU).1241 Oil Deposits(DFS)
- (DFS)Oil Deposits--HDOJ
- hdoj 1241 Oil Deposits
- hdoj 1241 Oil Deposits
- HDOJ 1241 Oil deposits
- HDOJ 1241 Oil Deposits
- HDOJ 1241 Oil Deposits
- HDOJ 1241 Oil Deposits
- 发一个很久以前遇到的线程死锁例子
- 第九周项目1-复数类中的运算符重载
- 游戏架构 云游戏(2)-网络环境问题
- 辽宁舰首次中期维护或历时半年 将更换大型部件
- 动态规划之状态压缩
- hdoj 1241 Oil Deposits (DFS)
- LTE学习笔记2之物理层
- Every Alphabet word describes girls
- 前端框架选择
- PsTools远程执行Windows命令
- 大范甘迪日天儿太热他
- js + php 读取、播放视频流 兼容firefox,chrome,ie,mac的safari,ios的safari,ios的微信浏览器(文件读取文件流篇)
- js编码问题
- C语言中的协程