Oil Deposits 搜索 bfs 强联通
Description
Input
Output
Sample Input
Sample Output
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100
const int inf=0x7fffffff; //无限大
int dx[]={,-,,,,-,,-};
int dy[]={,,,-,,-,-,};
int vis[][];
int n,m;
int ans=;
struct point
{
int x;
int y;
};
void bfs(int x,int y)
{
if(vis[x][y]!=)
return;
ans++;
queue<point> q;
point a;
a.x=x;
a.y=y;
q.push(a);
point now,next;
now.x=x;
now.y=y;
while(!q.empty())
{
now=q.front();
for(int i=;i<;i++)
{
next.x=now.x+dx[i];
next.y=now.y+dy[i];
if(next.x<||next.x>=n)
continue;
if(next.y<||next.y>=m)
continue;
if(vis[next.x][next.y]!=)
continue;
vis[next.x][next.y]=;
q.push(next);
}
q.pop();
}
}
int main()
{
while(cin>>n>>m)
{
memset(vis,,sizeof(vis));
if(n==&&m==)
break;
char a;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>a;
if(a=='*')
vis[i][j]=-;
else
vis[i][j]=;
}
}
ans=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(vis[i][j]==)
bfs(i,j);
}
}
cout<<ans<<endl;
}
return ;
}
Oil Deposits 搜索 bfs 强联通的更多相关文章
- HDU 1241 Oil Deposits (DFS/BFS)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- (简单) POJ 1562 Oil Deposits,BFS。
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- A - Oil Deposits(搜索)
搜索都不熟练,所以把以前写的一道搜索复习下,然后下一步整理搜索和图论和不互质的中国剩余定理的题 Description GeoSurvComp地质调查公司负责探测地下石油储藏. GeoSurvComp ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- Oil Deposits (HDU - 1241 )(DFS思路 或者 BFS思路)
转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82706189作者:Mercury_Lc 题目链接 题解:每个点(为被修改,是#)进 ...
- POJ 1562 Oil Deposits (并查集 OR DFS求联通块)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14628 Accepted: 7972 Des ...
- F - Oil Deposits 【地图型BFS+联通性】
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...
- 不撞南墙不回头———深度优先搜索(DFS)Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- hdu 1241 Oil Deposits (简单搜索)
题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...
随机推荐
- Nginx - Header详解
1. 前言 通过 HttpHeadersModule 模块可以设置HTTP头,但是不能重写已经存在的头,比如可能相对server头进行重写,可以添加其他的头,例如:Cache-Control,设置生存 ...
- JSP和Servlet那些事儿系列--HTTPS
原文:http://qingkangxu.iteye.com/blog/1614053 <JSP和Servlet那些事儿 >系列文章旨在阐述Servlet(Struts和Spring的MV ...
- 《Javascript启示录》要点汇总
前言:本文是阅读<Javascript启示录>后的一个读书笔记,对本书的要点进行了一个归纳,不是原创内容哦.要想详细了解相关内容,请阅读原书. 对象是由存储值的已命名属性组成的. Java ...
- Spring框架的基本使用(IOC部分)
Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架. Spring的好处 1.方便解耦,简化开发: Spring就是一个大工厂,专门负责生成Bean,可以将所有对象创建和依赖关 ...
- 一步步教你编写不可维护的 PHP 代码
译者注:这是一篇很棒文章,使用有趣的叙述方式,从反面讲解了作为一个优秀的 PHP 工程师,有哪些事情是你不能做的.请注意哦,此篇文章罗列的行为,都是你要尽量避免的. 随着失业率越来越高,很多人意识到保 ...
- 【转】Python验证码识别处理实例
原文出处: 林炳文(@林炳文Evankaka) 一.准备工作与代码实例 1.PIL.pytesser.tesseract (1)安装PIL:下载地址:http://www.pythonware.com ...
- (一)问候 HttpClient
第一节: HttpClient 简介 HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端编程工具包,并 ...
- Java事务管理之Hibernate
环境与版本 Hibernate 版本:Hibernate 4.2.2 (下载后的文件名为hibernate-release-4.2.2.Final.zip,解压目录hibernate-release- ...
- 有关c语言编程
有关C语言编程 统计代码"行数" 对于统计代码"行数",行数不包括空白行和注释行.程序改进如下: while(fgets (mystring , 100 , f ...
- PHP性能调优---php-fpm - 启动参数及重要配置详解
约定几个目录/usr/local/php/sbin/php-fpm/usr/local/php/etc/php-fpm.conf/usr/local/php/etc/php.ini 一,php-fpm ...