• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >C语言 > Oil Deposits

Oil Deposits

作者:chimchim04 字体:[增加 减小] 来源:互联网 时间:2017-12-08

chimchim04通过本文主要向大家介绍了Oil Deposits等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

                             Oil Deposits

 
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

0
1
2
2

 

 

 

 
代码:

 
#include<stdio.h> #include<string.h> char map[105][105]; int m,n; int go[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,1,-1,-1}; void dfs(int x,int y) { if(map[x][y]=='*') return ; map[x][y]='*'; for(int i=0;i<8;i++) { int a=x+go[i][0]; int b=y+go[i][1]; if(a>=0&&a<m&&b>=0&&b<n) dfs(a,b); } return ; } int main() { while(~scanf("%d%d",&m,&n)) { int num=0; if(m==0) break; for(int i=0;i<m;i++) for(int j=0;j<n;j++) scanf(" %c",&map[i][j]); for(int i=0;i<m;i++) for(int j=0;j<n;j++) { if(map[i][j]=='@') { num++; dfs(i,j); } } printf("%d\n",num); } return 0; }

 

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

相关文章

  • 2017-05-28c语言生成随机数的方法(获得一组不同的随机数)
  • 2017-05-28C++中引用&与取地址&的区别分析
  • 2017-05-28华为机试题之统计单词个数实例代码
  • 2017-05-28C++的静态联编和动态联编详解
  • 2017-05-28linux c程序中获取shell脚本输出的实现方法
  • 2017-05-28详解C语言中accept()函数和shutdown()函数的使用
  • 2017-05-28纯C语言:递归最大数源码分享
  • 2017-05-28visual studio 2015下boost库配置教程
  • 2017-05-28getdate()函数的用法实例
  • 2017-05-28C语言计算代码执行所耗CPU时钟周期

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 怎么实现类的成员函数作为回调函数
    • C语言实现的阶乘,排列和组合实例
    • C++之CNoTrackObject类和new delete操作符的重载实例
    • 基于指针的数据类型与指针运算小结
    • 封装常用正则表达式的用法
    • 详细总结C++的排序算法
    • C/C++ 读取16进制文件的方法
    • c++输出斐波那契数列示例分享
    • C# interface与delegate效能比较的深入解析
    • 解析linux 文件和目录操作的相关函数

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有