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 ...
随机推荐
- HUAS 1477 经营与开发(贪心)
考虑DP,令dp[i][j][k]当前在第i个星球,用了j次维修,k次开采后所获得的最大价值.复杂度为O(n^3).超时 如果我们发现,对于初始时能力值为w所能产生的最大价值y,初始时能力值为1所能产 ...
- hdu 1688 Sightseeing (最短路径)
Sightseeing Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Python fileinput模块详解
Python的fileinput模块可以快速对一个或多个文件进行循环遍历. import fileinput for line in fileinput.input(): process(line) ...
- Selector 模型
1.服务器端: import selectors import socket sel = selectors.DefaultSelector() #生成一个select对象 def accept(so ...
- BZOJ3926:[ZJOI2015]诸神眷顾的幻想乡——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3926 https://www.luogu.org/problemnew/show/P3346 幽香 ...
- IE的CSS渲染跟其它浏览器有什么不同
由于IE系浏览器对标准的支持不够好,导致Web开发中经常需要去处理浏览器兼容性问题,特别有些莫名其妙的问题很让人头疼,今天要说这个问题就是这样的,先从插入CSS的三种方法说起: 外部样式(Extern ...
- uboot 的命令体系
1.代码位置 (1)uboot命令体系的实现代码在uboot/common/cmd_xxx.c中.有若干个.c文件和命令体系有关.(还有command.c main.c也是和命令有关的) 2.传参方 ...
- Cropper
jQuery.cropper是一款使用简单且功能强大的图片剪裁jQuery插件.该图片剪裁插件支持图片放大缩小,支持图片旋转,支持触摸屏设备,支持canvas,并且支持跨浏览器使用. 官网:https ...
- 再续前缘-apache.commons.beanutils的补充
title: 再续前缘-apache.commons.beanutils的补充 toc: true date: 2016-05-32 02:29:32 categories: 实在技巧 tags: 插 ...
- SSH内存泄露及Spring Quartz问题
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明 http://www.blogbus.com/anoxia-logs/34360203.html 问题的起因: 为客户开发了一个系统权 ...