杭电(hdu)1241 Oil Deposits
来源:互联网 发布:用python直接写utf 编辑:程序博客网 时间:2024/05/21 11:26
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18625 Accepted Submission(s): 10729
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
深度优先搜索题
代码如下:
#include <iostream>#include <string>#include <cstring>using namespace std;char a[101][101];int v[101][101];int sum[101];int m,n,k;int count;int dir[8][2]={-1,0,1,0,-1,-1,-1,1,0,1,0,-1,1,-1,1,1};void dfs(int x,int y){ for(int i=0;i<=7;i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(xx>=1&&xx<=m&&yy>=1&&yy<=n&&a[xx][yy]=='@'&&v[xx][yy]==0) { v[xx][yy]=1; count++; dfs(xx,yy); } }}int main(){ while(cin>>m>>n,m) { k=0;int _count=0; memset(v,0,sizeof(v)); memset(sum,0,sizeof(sum)); for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) { cin>>a[i][j]; } for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) { if(a[i][j]=='@'&&v[i][j]==0) { v[i][j]=1; count=1; dfs(i,j); sum[k++]=count; } } for(int i=0;i<k;i++) { if(sum[i]>=1) _count++; } cout<<_count<<endl; }}
0 0
- 杭电(hdu)1241 Oil Deposits
- 杭电 hdu 1241 Oil Deposits
- Oil Deposits HDU杭电1241
- hdu 杭电 1241 Oil Deposits
- 【杭电1241】Oil Deposits(DFS)
- 杭电1241-Oil Deposits
- 杭电1241 Oil Deposits
- 杭电1241Oil Deposits
- 【杭电】[1241]Oil Deposits
- 杭电1241 Oil Deposits
- 杭电 1241 Oil Deposits
- HDU--杭电--1241--Oil Deposits--广搜
- Oil Deposits (HDU 1241)
- 【1241】Oil Deposits(HDU)
- 杭电1241--Oil Deposits(BFS)
- 杭电1241 Oil Deposits(搜索题)
- 杭电-1241 Oil Deposits(广搜)
- 杭电 1241 Oil Deposits 递归 DFS
- CodeForces 161D Distance in Tree(树形DP)
- Cocos Studio常用控件的使用
- 黑马程序员Java学习笔记之字符串String
- BC - Zball in Tina Town (质数 + 找规律)
- JAVA排序方法
- 杭电(hdu)1241 Oil Deposits
- oracle锁表解除
- 欧拉路AND欧拉回路
- MAPGIS 点位置坐标批量导出快速的方法
- Entity Framework相关文章汇总
- win7旗舰版下使用EasyBCD安装Ubuntu
- Improving Multiview Face Detection with Multi-Task Deep Convolutional Neural Networks 基于深度学习的人脸检测算法
- struts.objectFactory和struts.objectFactory.spring.autoWire
- 黑马程序员——IO流与File类