hdoj 1241 Oil Deposits
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16542 Accepted Submission(s):
9500
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.
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.
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.
/*
题意:给你一个规格为n*m的矩阵,由
字符'@'和'*'组成,问所有的@组成的区域
有多少块,(@组成的区域指向它的八个方向中其中一个方向
走依然是@)
题解:先找到第一个@,然后向这个@的八个方向查找,将所有查找到的
@都替换为*(将找过的位置覆盖,避免重复查找),看最后调用了dfs函数
多少次,就有多少个区域
*/ #include<stdio.h> ///hdu1241
#include<string.h>
#include<algorithm>
#define MAX 110
#define INF 0x3f3f3f
char map[MAX][MAX];
int n,m;
void dfs(int x,int y)
{
int i,j;
int move[8][2]={1,0,-1,0,0,1,0,-1,1,-1,1,1,-1,1,-1,-1};
if(map[x][y]=='@'&&0<=x&&x<n&&0<=y&&y<m)
{
map[x][y]='*';
for(i=0;i<8;i++)//搜索八个方向
dfs(x+move[i][0],y+move[i][1]);
//可以用上边的辅助数组进行搜索 ,也可以直接按照下边注释的
//方法搜索,其原理相同
// dfs(x-1,y);
// dfs(x+1,y);
// dfs(x,y-1);
// dfs(x,y+1);
// dfs(x-1,y-1);
// dfs(x-1,y+1);
// dfs(x+1,y-1);
// dfs(x+1,y+1);
}
return ;
}
int main()
{
int j,i,t,k;
while(scanf("%d%d",&n,&m),n|m)
{
for(i=0;i<n;i++)
scanf("%s",map[i]); int sum=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(map[i][j]=='@')
{
dfs(i,j);
sum++;
}
}
}
printf("%d\n",sum);
}
return 0;
}
hdoj 1241 Oil Deposits的更多相关文章
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
- HDU 1241 Oil Deposits(石油储藏)
HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Probl ...
- DFS(连通块) HDU 1241 Oil Deposits
题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...
- HDOJ/HDU 1241 Oil Deposits(经典DFS)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- 杭电1241 Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
随机推荐
- noj [1482] 嘛~付钱吧!(完全背包)
http://ac.nbutoj.com/Problem/view.xhtml?id=1482 [1482] 嘛~付钱吧! 时间限制: 1000 ms 内存限制: 65535 K 问题描述 大白菜带着 ...
- Android常用的工具类(转)
主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java.目前包括HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils.Prefer ...
- apache+tomcat 负载均衡
说明:本篇不面向无开发基础的人员,所以不会有软件下载,jdk安装等步骤.比较久远的东西了...... 1.系统环境 win7-64.jdk 2.软件列表: apache_2.2.24-x64-no-s ...
- vs2015 好用插件
备用一下,方便自己查阅 Viasfora 高亮,让自己看代码舒服 ClaudiaIDE 更换编辑器背景 Markdown Mode 编辑Markdown Glyphfriend 图像文字支持 Web ...
- hdu 4778
知道是状态压缩,但是不会做: 看题解学的: dp[i]表示现在状态是i,先手-后手的分数. #include<cstdio> #include<cstring> #includ ...
- uva 1475 - Jungle Outpost
半平面交,二分: 注意,题目的点是顺时针给出的: #include<cstdio> #include<algorithm> #include<cmath> #def ...
- 用Firefly创建第一个工程
原地址:http://blog.csdn.net/uxqclm/article/details/10382097 安装完成之后,在python script包中就存在 firefly-admin的工具 ...
- ASP.NET Application,Session,Cookie和ViewState等对象用法和区别 (转)
在ASP.NET中,有很多种保存信息的内置对象,如:Application,Session,Cookie,ViewState和Cache等.下面分别介绍它们的用法和区别. 方法 信息量大小 作用域和保 ...
- maven 依赖排除
在项目中遇到一个问题,项目使用spring 3.x,引用了某些包,这些包又依赖了spring2.x,造成项目无法启动.这种情况就需要用到maven的依赖排除,配置如下: 使用以下代码排除依赖xxxx引 ...
- ANDROID_MARS学习笔记_S01原始版_009_下载文件
一.代码1.xml(1)main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayo ...