POJ 1562:Oil Deposits
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 14462 | Accepted: 7875 |
Description
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
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
Sample Input
- 1 1
- *
- 3 5
- *@*@*
- **@**
- *@*@*
- 1 8
- @@****@*
- 5 5
- ****@
- *@@*@
- *@**@
- @@@*@
- @@**@
- 0 0
Sample Output
- 0
- 1
- 2
- 2
给一个表,问连着的@都多少堆,对角线、上下左右挨着一个就算连上了。
深搜入门题,对准@可劲的搜,能搜100块绝不搜80。计算循环了多少次即可。
代码:
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <cstring>
- #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<<result<<endl;
- }
- return 0;
- }
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1562:Oil Deposits的更多相关文章
- HDU 1241 :Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- HDU 1241 Oil Deposits (DFS)
题目链接:Oil Deposits 解析:问有多少个"@"块.当中每一个块内的各个"@"至少通过八个方向之中的一个相邻. 直接从"@"的地方 ...
- POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)
题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...
- POJ 1562 Oil Deposits (并查集 OR DFS求联通块)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14628 Accepted: 7972 Des ...
- (简单) POJ 1562 Oil Deposits,BFS。
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- [POJ] 1562 Oil Deposits (DFS)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16655 Accepted: 8917 Des ...
- HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil de ...
- Oil Deposits(poj 1526 DFS入门题)
http://poj.org/problem?id=1562 ...
- HDU 1562 Oil Deposits
题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...
随机推荐
- vue+element 递归上传图片
直接上代码. <template> <div> <el-upload action="http://localhost:3000/pic ...
- 一个小证明(题解 P5425 Part1)
所以这道题为什么可以这样做 嗯,我也不知道,不过我是来填坑的. \(Q\):为什么要把牛分成\(1\),\(1\)......\(N-K+1\)这样的\(K\)组呢? \(A\):我们设第\(i\)组 ...
- php二位数组排序(按子元素排序)
array_multisort(array_column($mainTree[$note]["beCalls"], "wtp"), SORT_DESC, arr ...
- 039、Java中逻辑运算之普通与运算“&”
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- 06.Delphi接口的不对等的多重继承
uSayHello代码如下 unit uSayHello; interface uses SysUtils, Windows, Messages, Classes, Graphics, Control ...
- docker安装并设置开机启动(Linux)
docker 开机启动: systemctl enable docker 使用的linux系统为CentOS7.2 docker分为CE和EE版本,EE版本收费,一般我们使用CE版本就满足要求了 do ...
- Qt编写的项目作品2-控件属性设计器(组态)
一.功能特点 自动加载插件文件中的所有控件生成列表,默认自带的控件超过120个. 拖曳到画布自动生成对应的控件,所见即所得. 右侧中文属性栏,改变对应的属性立即应用到对应选中控件,直观简洁,非常适合小 ...
- 点亮一个LED之参数传递规则
1 说明 实验平台: JZ2440 CPU: S3C2440 2 ARM-THUMB Procedure Call Standard(ATPCS: ARM-Thumb过程调用标准) 图1 ...
- Golang的循环结构-for语句
Golang的循环结构-for语句 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.for循环语法 循环结构在生活中的场景也非常的多,比如: ()上班族们每天朝九晚五的生活; ( ...
- duilib之重写BUTTON按钮
在使用BUTTON过程中,有时候发现一些属性不够用,或要从新绘制BUTTON按钮,那该如何操作?其实很简单,只需要继承CButtonUI类就行. 创建类CMyButtonUI,继承CButtonUI, ...