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 ...
随机推荐
- windows默认TEMP环境
留着是为了等出问题的时候能找着改回来 Administrator 的用户变量 TEMP %USERPROFILE%\AppData\Local\Temp TMP %USERPRO ...
- 发送tcp的时候,数据包是如何拷贝的
发送数据包的时候,用户态的数据包是如何拷贝到内核的kiovec msghd 结构体 icmp是走sock吗? 每一个skb_buffer的大小都是固定的吗?所以有skb_available这样的函数 ...
- mysql向上递归&向下递归
工作记录 向上递归函数test: BEGIN ); ); SET sTemp = '$'; SET sTempChd =cast(rid as CHAR); WHILE sTempChd is not ...
- title & abbr & tooltips
title & abbr & tooltips https://dmitrybaranovskiy.github.io/raphael/ <abbr title="Sc ...
- delphi怎样单步调试
在delphi的IDE编辑窗口里,主菜单->Run->Step Over或者主菜单->Run->Trace Into单步调试有两种方式:一种是Step Over,快捷键是F8, ...
- js 复制到剪贴板 兼容还得自己想办法
clipboard.js https://github.com/zenorocha/clipboard.js/ 主要问题还是ie8, 可以使用ie 特有的方法 if (window.clipboard ...
- springBoot @Enable*注解的工作原理
使用注解实现异步 RunnableDemo类 package com.boot.enable.bootenable; import org.springframework.scheduling.ann ...
- BZOJ 2306 幸福路径(DP)
题解来源:http://www.cnblogs.com/jianglangcaijin/p/3799494.html 最后必然是走了一条链,或者是一个环(一直绕),或者是一条链加一个环.设f[i][j ...
- 【刷题】洛谷 P4329 [COCI2006-2007#1] Bond
题意翻译 有 \(n\) 个人去执行 \(n\) 个任务,每个人执行每个任务有不同的成功率,每个人只能执行一个任务,求所有任务都执行的总的成功率. 输入第一行,一个整数 \(n\) ( \(1\leq ...
- 剑桥offer(21~30)
21.题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 还不 ...