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. ...
随机推荐
- 使用Netcat进行攻击
https://www.freebuf.com/column/135007.html 在网上找到了一个开启了ftp服务的服务: http://static.vhdong.com/Upload/Temp ...
- linux系统iostat命令详解
iostat -k 3 5 (以KB为单位,每3秒统计一次,共统计5次) • avg-cpu: 总体cpu使用情况统计信息,对于多核cpu,这里为所有cpu的平均值 %user 用户空 ...
- python 之datetime库学习
# -*- coding:utf-8 -*- import refrom datetime import datetime, timezone, timedelta def rec_time(): ...
- Jquery获取radio单选按钮的value与后面的文字
一组单选按钮如图: <input name="classId" value="8afa94f45ba3e2c1015ba3fac6c00000" type ...
- RESTful API 和 Django REST framework
100天 cmdb最后一天 #RESTful API - 定义规范 如get就是请求题 - 面向资源编程 把网络任何东西都当作资源 #给一个url,根据方法的不同对资源做不同的操作 #返回结果和状态码 ...
- 不同意义的new和delete
补充说明: new/delete是运算符而非函数,operator new/delete并非是new/delete的重载.事实上,我们无法自定义new/delete的行为: operator new/ ...
- (一)问候 HttpClient
第一节: HttpClient 简介 HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端编程工具包,并 ...
- (四)SpringMvc文件上传
第一节:SpringMvc单文件上传 第二节:SpringMvc多文件上传
- AARRR:数据运营模型
一.基础知识 产品经理 <增长黑客>数据分析基础 -- 获取(Acquisition)-- 激活(Activation)-- 留存(Retention)-- 收入(Revenue)-- ...
- Hex Dump In Many Programming Languages
Hex Dump In Many Programming Languages See also: ArraySumInManyProgrammingLanguages, CounterInManyPr ...