博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oil Deposits(poj 1526 DFS入门题)
阅读量:6908 次
发布时间:2019-06-27

本文共 1899 字,大约阅读时间需要 6 分钟。

                                                                                  
                 Oil Deposits
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 12595   Accepted: 6868

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 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

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 题目大意:如果'@'周围的8个方向有'@'就认为它们是同一油田。求总油田的个数。 本题是dfs的入门题,我的dfs只能用很烂来形容,dfs利用了栈的思想,先进后出。
#include 
#include
#include
#include
#include
#define N 1000001using namespace std;int n,m;char map[101][101];int v[101][101];int jx[]={
1,1,1,-1,-1,-1,0,0};int jy[]={-1,0,1,-1,0,1,-1,1};void dfs(int x,int y){ v[x][y]=1; int tx,ty; for(int i=0;i<8;i++) { tx=x+jx[i]; ty=y+jy[i]; if(tx>=0&&tx
=0&&ty

 

转载地址:http://aogdl.baihongyu.com/

你可能感兴趣的文章
亚信安全预警:一大波勒索软件变种来袭
查看>>
手机网民达7.8亿 移动网络安全不容忽视
查看>>
《算法基础》——3.4 有序链表
查看>>
《UNIX网络编程 卷2:进程间通信(第2版)》——2.3 创建与打开IPC通道
查看>>
商务直播跨海云:商务直播的那点事
查看>>
《MATLAB智能算法超级学习手册》一一第1章 MATLAB基础知识
查看>>
《Docker进阶与实战》——2.4节SparkContext概述
查看>>
《算法基础:打开算法之门》一导读
查看>>
《开源思索集》一成功的开源软件都有什么样的特点
查看>>
《Cisco IOS XR技术精要》一1.2 运营商级NOS需求
查看>>
Mozilla 拟在浏览器中增基于网页的虚拟现实功能
查看>>
《部署IPv6网络(修订版)》一2.3 IPv6 Internet控制消息协议(ICMPv6)
查看>>
《趣学CCNA——路由与交换》——6.1节Cisco设备的管理与配置
查看>>
Android 被曝多处安全漏洞 影响所有版本
查看>>
《数据结构与算法 C语言版》—— 3.2栈的应用举例
查看>>
在Linux上的虚拟机上启动Oracle上报ORA-00845: MEMORY_TARGET not supported on this system的问题解决...
查看>>
《Cisco IOS XR技术精要》一4.3 配置管理组件
查看>>
《社会智能与综合集成系统》—第2章参考文献
查看>>
《Adobe Photoshop CS5中文版经典教程(全彩版)》—第2课2.4节在Camera Raw中调整颜色...
查看>>
《Adobe Premiere Pro视频编辑指南(第2版)》——水银回放引擎
查看>>