Oil Deposits(dfs)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15291 Accepted Submission(s): 8787
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 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.
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.
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,m;
char grid[120][120];
int vis[120][120];
struct node{
int x,y;
};
void in_put()
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;++i)
scanf("%s",grid[i]+1);
}
int check(node v)
{
if(!vis[v.x][v.y]&&v.x>=1&&v.x<=n&&v.y>=1&&v.y<=m&&grid[v.x][v.y]=='@')
return 1;
else return 0;
}
void dfs(node v)
{
node nex;
vis[v.x][v.y]=1;grid[v.x][v.y]='?'; nex.x=v.x+1;nex.y=v.y;if(check(nex)) dfs(nex);
nex.x=v.x+1;nex.y=v.y+1;if(check(nex)) dfs(nex);
nex.x=v.x+1;nex.y=v.y-1;if(check(nex)) dfs(nex);
nex.x=v.x;nex.y=v.y-1;if(check(nex)) dfs(nex);
nex.x=v.x;nex.y=v.y+1;if(check(nex)) dfs(nex);
nex.x=v.x-1;nex.y=v.y-1;if(check(nex)) dfs(nex);
nex.x=v.x-1;nex.y=v.y+1;if(check(nex)) dfs(nex);
nex.x=v.x-1;nex.y=v.y;if(check(nex)) dfs(nex);
}
int main()
{
while(scanf("%d%d",&n,&m))
{
int cnt=0;node now;
if(!n&&!m) break;
in_put();
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
if(grid[i][j]=='@')
{now.x=i;now.y=j;dfs(now);cnt++;} printf("%d\n",cnt);
}
}
2
Oil Deposits(dfs)的更多相关文章
- 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(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- UVa572 Oil Deposits DFS求连通块
技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...
- HDU 1241 Oil Deposits (DFS/BFS)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU-1241 Oil Deposits (DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- UVa 572 Oil Deposits(DFS)
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil ...
- [POJ] 1562 Oil Deposits (DFS)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16655 Accepted: 8917 Des ...
- Oil Deposits(dfs水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...
随机推荐
- 【python】dict的注意事项
1. key不能用list和set 由于列表是易变的,故不可做key.如果使用会报错 但是元组可以做key 2.遍历方法 for key in somedict: pass 速度快,但是如果要删除元素 ...
- Sql存储过程
下面的存储过程从四个表的联接中返回所有作者(提供了姓名).出版的书籍以及出版社.该存储过程不使用任何参数. USE pubs IF EXISTS (SELECT name FROM sysobject ...
- React Native实例之房产搜索APP
React Native 开发越来越火了,web app也是未来的潮流, 现在react native已经可以完成一些最基本的功能. 通过开发一些简单的应用, 可以更加熟练的掌握 RN 的知识. 在学 ...
- svn不知道这样的主机
重做服务器后,计算机名称肯定是不一样的.我们之前的项目还是老计算机名字,只要更改一下计算机名字即可实现.或者更改
- Tiny Rss Reader - 迷你RSS阅读器
发布新软件 TinyRss: Windows平台上的一个小巧的Rss阅读器. 用户界面: 项目地址: https://github.com/movsb/tinyrss.git 测试下载: http:/ ...
- AOJ789 买酒
买酒 Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBTotal Submission: 70 Submis ...
- Java 类装载器
类装载器 基本概念: 顾名思义,类加载器(class loader)用来把Java 类动态的加载到 Java 虚拟机中.也就是说当程序需要某个类时,类加载器就把这个类的二进行加入到虚拟机中. 类加载器 ...
- hihoCoder 1391 Countries【预处理+排序+优先队列】2016北京网络赛
题目:http://hihocoder.com/problemset/problem/1391 题目大意: A和B两个国家互射导弹,每个国家都有一个防御系统,在防御系统开启的时间内可以将到达本国的导弹 ...
- 在Salesforce中通过编写C#程序调用dataloadercliq的bat文件取触发调用data loader来批量处理数据
通过这篇文章 http://www.cnblogs.com/mingmingruyuedlut/p/3413903.html 我们已经知道了Data Loader可以对Salesforce的Objec ...
- Vue#Class 与 Style 绑定
绑定HTMLCLASS 在我没看这之前,我觉得要写绑定class ,应该像绑定数据一样这么写 class ={{class-a}} 看官方教程时,不推荐这么写,推荐这样 v-bind:class=&q ...