深搜专题初步-1005
来源:互联网 发布:网络课程平台比较好的 编辑:程序博客网 时间:2024/06/03 13:53
1005
总提交: 15 测试通过: 12
描述
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.
输入
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.
输出
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.
样例输入
1 1*3 5*@*@***@***@*@*1 8@@****@*5 5 ****@*@@*@*@**@@@@*@@@**@0 0
样例输出
0122
代码:
#include<stdio.h>#include<string.h>char map[105][105];int n,m;int dir[][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};bool dfs(int i,int j){ int xx,yy,k; map[i][j]='*'; for(k=0;k<8;k++) { xx=i+dir[k][0]; yy=j+dir[k][1]; if(xx>-1&&xx<n&&yy>-1&&yy<m) { if(map[xx][yy]=='@') dfs(xx,yy); } } }int main(){int i,j,sum;while(~scanf("%d%d",&n,&m)&&n&&m){sum=0;for(i=0;i<n;i++)scanf("%s",map[i]);for(i=0;i<n;i++){for(j=0;j<m;j++){if(map[i][j]=='@'){dfs(i,j);sum++;}}}printf("%d\n",sum);}}深搜起步题;
- 深搜专题初步-1005
- 深搜专题初步-1002
- 深搜专题初步-1001
- 深搜专题初步-1003
- 深搜专题初步-1004
- 深搜专题初步-1006
- 深搜专题
- 深搜专题
- 深搜专题小结
- 深搜专题(DFS大法好!)
- 深搜专题——木棒
- 专题一 · 1005
- 专题二1005
- 专题二 · 1005
- 专题二 1005
- 专题三1005
- SDAU dp专题 1005
- 专题三1005
- bash shell 使用技巧
- 排序算法总结一(c++版)
- 053第5
- Java事务与JTA
- HashMap遍历效率测试
- 深搜专题初步-1005
- 2015内蒙古公务员面试备考:标准化考试如何非模式化答题
- 工厂方法模式与抽象工厂模式
- 【LeetCode】Contains Duplicate II
- 【Objective-C】 OC编码规范
- 【转】 Levenberg-Marquardt 算法快速入门教程
- Android studio 导入github工程
- Windows服务安装异常:System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
- Jvm基础(1)-Java运行时数据区