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 ...
随机推荐
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- 真机测试无缘无故finish了。程序也没有启动
去钥匙串里边把多余的证书删除, 然后reset xcode - preference - 选中你的appleID - iOS Development - reset
- apache vhost
httpd.conf: Include "F:/wamp/alias/*" <Directory "F:\wamp\www"> Options ...
- September 2nd 2016 Week 36th Friday
How does the world look through your eyes? 你眼里的世界是什么样子的? How does the world look through your eyes? ...
- poj2492(种类并查集/各种解法)
题目链接: http://poj.org/problem?id=2492 题意: 有t组测试数据, 对于每组数据,第一行n, m分别表示昆虫的数目和接下来m行x, y, x, y表示教授判断x, y为 ...
- 阿里云的RDS 查看binlog日志的方法
按时间点反后台备份的binlog日志从阿里云导出来,然后用mysqlbinlog查看日志内容: # mysqlbinlog -vv --base64-output=decode-rows mysql- ...
- PHP 获取图像信息 getimagesize 函数
getimagesize() 函数用于获取图像尺寸,类型等信息. imagesx() 函数用于获取图像的宽度. imagesy() 函数用于获取图像的高度. getimagesize() getima ...
- 突破python缺陷,实现几种自定义线程池 以及进程、线程、协程的介绍
Python线程 Threading用于提供线程相关的操作,线程是应用程序中工作的最小单元. #!/usr/bin/env python # -*- coding:utf-8 -*- import t ...
- SQL索引及视图常用语法
ALTER TABLE department ADD INDEX dept_name_idx (name); SHOW INDEX FROM department \G ALTER TABLE dep ...
- 缓慢变化维 (Slowly changing dimension)
维度建模的数据仓库中,有一个概念叫Slowly Changing Dimensions,中文一般翻译成"缓慢变化维",经常被简写为SCD.缓慢变化维的提出是因为在现实世 ...