博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1562:Oil Deposits
阅读量:6333 次
发布时间:2019-06-22

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

Oil Deposits
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 14462   Accepted: 7875

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

给一个表,问连着的@都多少堆,对角线、上下左右挨着一个就算连上了。

深搜入门题,对准@可劲的搜,能搜100块绝不搜80。计算循环了多少次即可。

代码:

#include 
#include
#include
#include
#include
#include
#pragma warning(disable:4996)using namespace std;int row,col;char value[110][110];int met[110][110];void dfs(int i,int j){ met[i][j]=1; if(met[i-1][j-1]==0&&value[i-1][j-1]=='@') dfs(i-1,j-1); if(met[i-1][j]==0&&value[i-1][j]=='@') dfs(i-1,j); if(met[i-1][j+1]==0&&value[i-1][j+1]=='@') dfs(i-1,j+1); if(met[i][j+1]==0&&value[i][j+1]=='@') dfs(i,j+1); if(met[i+1][j+1]==0&&value[i+1][j+1]=='@') dfs(i+1,j+1); if(met[i+1][j]==0&&value[i+1][j]=='@') dfs(i+1,j); if(met[i+1][j-1]==0&&value[i+1][j-1]=='@') dfs(i+1,j-1); if(met[i][j-1]==0&&value[i][j-1]=='@') dfs(i,j-1);}int main(){ int i,j; while(cin>>row>>col) { if(row+col==0) break; memset(met,0,sizeof(met)); for(i=1;i<=row;i++) { cin>>value[i]+1; } int result=0; for(i=1;i<=row;i++) { for(j=1;j<=col;j++) { if(value[i][j]=='@'&&met[i][j]==0) { dfs(i,j); result++; } } } cout<
<

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/lightspeedsmallson/p/4785800.html

你可能感兴趣的文章
敏捷个人:通过实践TOGAF来思考如何学习并应用新的方法?
查看>>
Android系统的开机画面显示过程分析(6)
查看>>
vivo Hi-Fi+QQ音乐 数字音乐市场的一剂良方
查看>>
Cocos2d-x 3.2 异步动态加载 -- 保卫萝卜开发总结
查看>>
聚焦触宝反侵权事件:中国创业者用什么护航海外市场大门
查看>>
AOP技术基础
查看>>
Android系统进程间通信(IPC)机制Binder中的Server启动过程源代码分析(2)
查看>>
无线802.11n 2.4G与5G性能测试
查看>>
子域名信息收集攻略
查看>>
[Android]开发数独游戏思路分析过程
查看>>
SpreadJS 类Excel表格控件 - V12 新特性详解
查看>>
理解并取证:IPv6与IPv4在报文结构上的区别
查看>>
EOS主网上线只是开始,如何运营决定未来
查看>>
不用Visual Studio,5分钟轻松实现一张报表
查看>>
(译)如何使用cocos2d和box2d来制作一个Breakout游戏:第一部分
查看>>
计算机图形学(一) 图形系统综述
查看>>
持续集成(CI)- 几种测试的区别(摘录)
查看>>
多用户虚拟Web3D环境Deep MatrixIP9 1.04发布
查看>>
求高手,求解释
查看>>
[MSSQL]NTILE另类分页有么有?!
查看>>