Oil Deposits(DFS)
来源:互联网 发布:阿里云服务器备案 编辑:程序博客网 时间:2024/05/20 08:44
A - Oil Deposits
Crawling in process...Crawling failedTime Limit:1000MS Memory Limit:32768KB64bit IO Format:%I64d & %I64uSubmit
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#include<stdio.h>#include<string.h>#include<algorithm>#include<cstring>#include<cmath>using namespace std;int n,m,vis[105][105],ans;char a[105][105];int dir[8][2]= {1,0,0,1,-1,0,0,-1,1,1,-1,-1,1,-1,-1,1};void dfs(int x,int y){ for(int i=0; i<8; i++) { int di=x+dir[i][0]; int dj=y+dir[i][1]; if(di>=0&&di<n&&dj>=0&&dj<m&&a[di][dj]=='@') { a[di][dj]='*'; dfs(di,dj); } }}int main(){ while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; ans=0; memset(vis,0,sizeof(vis)); for(int i=0; i<n; i++) scanf("%s",a[i]); for(int i=0; i<n; i++) for(int j=0; j<m; j++) { if(a[i][j]=='@') { a[i][j]='*'; dfs(i,j); ans++; } } printf("%d\n",ans); } return 0;}
0 0
- Oil Deposits hdu1241 dfs
- Oil Deposits poj DFS
- POJ1562:Oil Deposits(DFS)
- HDU1241:Oil Deposits(DFS)
- hdu1241(DFS Oil Deposits )
- UVa572 Oil Deposits(DFS)
- Oil Deposits DFS水题
- Oil Deposits BFS+DFS
- Oil Deposits uva DFS
- HDU1241:Oil Deposits(DFS)
- 【搜索-DFS】Oil Deposits
- Oil Deposits(DFS)
- poj1562 Oil Deposits(DFS)
- HDU1241 Oil Deposits DFS
- HDU1241 Oil Deposits DFS
- Oil Deposits(dfs深搜)
- UVA572 Oil Deposits dfs
- Oil Deposits(基础dfs)
- Python中iter函数用法简述
- javascript学习日记--parseInt()/parseFloat()
- 博弈论与逻辑思维(传教士与妻子忠贞的问题)
- Centos6.5安装mysql不能启动,应该安装mysql-server
- Roman to Integer
- Oil Deposits(DFS)
- 程序员的基础生存技能 -- 关于搜索引擎的小贴士
- Linux 上的基础网络设备详解
- linux arm移植触摸屏tslib
- python多进程队列的2种实现方法
- ArrayAdapter
- Building an MFC project for a non-Unicode character set is deprecated
- 中序后序确定二叉树的前序序列
- hdu2437