Description

The 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

The 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.
 

Output

For 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.
 

Sample Input

1 1 * 3 5 *@*@* **@** *@*@* 1 8 @@****@* 5 5 ****@ *@@*@ *@**@ @@@*@ @@**@ 0 0
 

Sample Output

0 1 2 2

#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 强联通的更多相关文章

  1. HDU 1241 Oil Deposits (DFS/BFS)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  2. (简单) POJ 1562 Oil Deposits,BFS。

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  3. A - Oil Deposits(搜索)

    搜索都不熟练,所以把以前写的一道搜索复习下,然后下一步整理搜索和图论和不互质的中国剩余定理的题 Description GeoSurvComp地质调查公司负责探测地下石油储藏. GeoSurvComp ...

  4. HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. Oil Deposits (HDU - 1241 )(DFS思路 或者 BFS思路)

    转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82706189作者:Mercury_Lc 题目链接 题解:每个点(为被修改,是#)进 ...

  6. POJ 1562 Oil Deposits (并查集 OR DFS求联通块)

    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14628   Accepted: 7972 Des ...

  7. F - Oil Deposits 【地图型BFS+联通性】

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...

  8. 不撞南墙不回头———深度优先搜索(DFS)Oil Deposits

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  9. hdu 1241 Oil Deposits (简单搜索)

    题目:   The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...

随机推荐

  1. from setuptools import setup ImportError: No module named setuptools【转】

    转自:http://www.cnblogs.com/chinacloud/archive/2010/12/24/1915644.html from setuptools import setupImp ...

  2. 『实践』Java Web开发之分页(ajax)

    1.需要用到的jar包.js文件 JSONArray().fromObject()需要的jar包: (1)commons-beanutils-1.8.3.jar (2)commons-collecti ...

  3. python网络编程--线程递归锁RLock

    一:死锁 所谓死锁:是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这些永远在互相等待的进 ...

  4. Linux下配置Samba服务器全过程

    Linux下配置Samba服务器全过程 user级别的samba的配置 http://www.linuxidc.com/Linux/2014-11/109234.htm http://www.linu ...

  5. virtualenv,virtualenvwrapper安装及使用

    1.安装 # 安装: (sudo) pip install virtualenv virtualenvwrapper # centos7下 pip install virtualenv virtual ...

  6. Kubernetes 部署kafka ACL(单机版)

    一.概述 在Kafka0.9版本之前,Kafka集群时没有安全机制的.Kafka Client应用可以通过连接Zookeeper地址,例如zk1:2181:zk2:2181,zk3:2181等.来获取 ...

  7. java正则表达式(转)

    1.验证email public static void main(String[] args) { // 要验证的字符串 String str = "service@xsoftlab.ne ...

  8. Linux下的堆off-by-one的利用

    这篇稿子已经投到了360安全播报,http://bobao.360.cn/learning/detail/3113.html

  9. Linux密码策略-密码长度-密码复杂度

    1.设置密码长度 vim /etc/pam.d/system-authpassword requisite pam_cracklib.so try_first_pass retry=3 minlen= ...

  10. C# POS 小票打印

    网上查了好多资料终于让我捣鼓出来了! public partial class Models_JXC_Sale_actNewSalePage : WebPartBase { public string ...