hdoj1241 Oil Deposits
来源:互联网 发布:淘宝平板电脑客户端 编辑:程序博客网 时间:2024/06/05 07:58
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18982 Accepted Submission(s): 10940
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<stdio.h>#include<algorithm>using namespace std;#include<string.h>#define N 1010int n,m;char map[N][N];int visit[N][N];int dx[8]={1,0,0,-1,1,1,-1,-1};//八个方向搜索 int dy[8]={0,1,-1,0,1,-1,1,-1};int judge(int x,int y){ return x>=0&&x<n&&y>=0&&y<m&&map[x][y]!='*'&&visit[x][y]==0; }void dfs(int x,int y)//深搜 { int i,j; visit[x][y]=1; for(i=0;i<8;i++) { int tx=x+dx[i]; int ty=y+dy[i]; if(judge(tx,ty)) { dfs(tx,ty); } }}int main(){ int i,j,k; while(scanf("%d%d",&n,&m)!=EOF&&(n!=0||m!=0)) { for(i=0;i<n;i++) { scanf("%s",map[i]); } memset(visit,0,sizeof(visit)); k=0; for(i=0;i<n;i++) for(j=0;j<m;j++) { if(map[i][j]=='@'&&visit[i][j]==0) { k++; dfs(i,j); } } printf("%d\n",k); }}
0 0
- hdoj1241 Oil Deposits
- HDOJ1241 Oil Deposits
- hdoj1241 Oil Deposits
- Oil Deposits<hdoj1241>
- HDOJ1241 Oil Deposits(DFS模板题)
- HDOJ1241 Oil Deposits(DFS,八连通块)
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- android学习路线:如何成长为高级工程师
- thinkphp-生成xml的实例——和js轮换图实现
- 解决古董机升级成Win 10后开机唤醒长时间黑屏的问题
- VideoView的使用示例
- Ajax实现瀑布流动态加载网页
- hdoj1241 Oil Deposits
- nyoj 42 一笔画问题
- listview优化
- 字符流 FileWriter FileReader 字节流 InputStream OutputStream FileOutputStream FileInputStream 的使用
- 继戴尔670亿收购EMC后,科技界钱多的让人窒息的五大收购案
- 常量指针、指针常量、指针函数、函数指针、指针数组、数组指针区别在哪里?
- Android知识点目录(Updating……)
- 四则运算 java
- 一个简单自定义View控件