hdu 1241Oil Deposits(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13137 Accepted Submission(s):
7611
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.
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring> using namespace std; int dir[][]= {,,,-,,,-,,,,,-,-,,-,-};
char map[][];
int a,b,vis[][],k; struct node
{
int x,y;
int t;
} s,ss; queue<node>q,qq;
int bfs()
{
while (!q.empty())
{
s=q.front();
q.pop();
//vis[s.x][s.y]=1;
for (int i=; i<; i++)
{
int x=s.x+dir[i][];
int y=s.y+dir[i][];
//int t=s.t+1;
if (x>=&&x<a&&y>=&&y<b)
{
if (!vis[x][y]&&map[x][y]=='@')
{
ss.x=x;
ss.y=y;
map[ss.x][ss.y]='*';
//vis[x][y]=1;
q.push(ss);
} }
}
}
} int main ()
{
while (scanf("%d%d",&a,&b)!=EOF)
{
memset(vis,,sizeof(vis));
if (a==&&b==)
break;
for (int i=; i<a; i++)
{
getchar();
for (int j=; j<b; j++)
{
scanf("%c",&map[i][j]);
}
}
//int k=0;
for (int i=k=; i<a; i++)
{
for (int j=; j<b; j++)
{
if (map[i][j]=='@')
{
k++;
s.x=i;
s.y=j;
map[s.x][s.y]='*';
vis[s.x][s.y]=;
q.push(s);
bfs();
}
}
}
printf ("%d\n",k);
}
return ;
}
hdu 1241Oil Deposits(BFS)的更多相关文章
- HDU 1241Oil Deposits (DFS)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- hdu 1241Oil Deposits(dfs模板)
题目链接—— http://acm.hdu.edu.cn/showproblem.php?pid=1241 首先给出一个n*m的字符矩阵,‘*’表示空地,‘@’表示油井.问在这个矩阵中有多少组油井区? ...
- HDU 1241 - Oil Deposits - [BFS]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 题意: 求某块平面上,连通块的数量.一个油田格子若周围八个方向也有一个油田格子,则认为两者相连通 ...
- HDU 1241 Oil Deposits bfs 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=1241 对每个还未访问的点bfs,到达的点都标为一块,最后统计有多少块即可 #include <cstdio ...
- HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4528 小明系列故事——捉迷藏 Time Limit: 500/200 MS (Java/O ...
- hdu 1072 Nightmare (bfs+优先队列)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 Description Ignatius had a nightmare last night. H ...
- HDU 3533 Escape bfs 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=3533 一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了 需要注意的是: 1.人不能经过炮台 2 ...
- hdu 2389(最大匹配bfs版)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2389 思路:纯裸的一个最大匹配题,不过悲摧的是以前一直用的dfs版一直过不了,TLE无数次啊,然后改成 ...
- HDU 1495 非常可乐 BFS 搜索
http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目就不说了, 说说思路! 倒可乐 无非有6种情况: 1. S 向 M 倒 2. S 向 N 倒 3. N ...
随机推荐
- dedecms 后台登录地址
dedecms 后台登录地址 http://www.域名.com/member/index.php
- perf中branch-filter到底是干嘛的?
./arch/x86/events/intel/core.c:2161: data.br_stack = &cpuc->lbr_stack;./arch/x86/e ...
- 深入理解:java类加载器
概念理解:Java类加载器总结 1.深入理解Java类加载器(1):Java类加载原理解析 2.深入理解Java类加载器(2):线程上下文类加载器
- bzoj3676-回文串
给出一个字符串,一个子串的出现值为字串出现次数乘以长度,求所有回文串中最大的出现值. 分析 回文自动机模版题,建出自动机后直接统计即可. 回文自动机 类似于后缀自动机,不过一条边\((u,v,c)\) ...
- 【bzoj1858】[Scoi2010]序列操作 线段树区间合并
题目描述 lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要么是1,现在对于这个序列有五种变换操作和询问操作: 0 a b 把[a, b]区间内的所有数全变成0 1 a b ...
- 编译 python 生成静态库 libpython2.7.so
由于我们是C++作驱动的Python开发,驱动需要加上Python静态库libpython2.7.so.libpython2.7.so.1.0.libpython2.7.a.此处我想在python源码 ...
- pascal语言中学版整理
P1:主菜单File中的Command shell选项,可以暂时退出Pascal,进入DOS提示符状态,但Pascal仍然驻留在内存中.输入命令exit即可返回Pascal. P3:Edit菜单中Un ...
- A表数据插入到B表(表结构不一致)
D_A 有E\F\H 3字段 D_B 有 A\B\C\D\E\ID 字段 将 D_B 个别字段插入到D_A 表 INSERT INTO D_A(E,F,H) select B,A,ID from ...
- BZOJ1257:[CQOI2007]余数之和——题解+证明
http://www.lydsy.com/JudgeOnline/problem.php?id=1257 Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod ...
- Eclipse配置web开发环境
eclipse的web配置: eclipse:Eclipse Java EE IDE for Web Developers. Version: Helios Service Release 1 下载地 ...