HDU 1241 Oil Deposits bfs 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=1241
对每个还未访问的点bfs,到达的点都标为一块,最后统计有多少块即可
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=101;
const int inf=0x3fffffff;
char maz[maxn][maxn];
int id[maxn][maxn];
int n,m,cnt; queue<int> que;
const int dx[8]={0,0,1,-1,1,1,-1,-1};
const int dy[8]={1,-1,0,0,1,-1,1,-1};
bool in(int x,int y){
return x>=0&&x<n&&y>=0&&y<m;
}
void bfs(int sx,int sy){
while(!que.empty())que.pop();
id[sx][sy]=++cnt;
que.push(sx*maxn+sy);
while(!que.empty()){
int x=que.front()/maxn,y=que.front()%maxn;que.pop();
for(int i=0;i<8;i++){
int tx=x+dx[i],ty=y+dy[i];
if(in(tx,ty)&&maz[tx][ty]!='*'&&id[tx][ty]==-1){
id[tx][ty]=id[x][y];
que.push(tx*maxn+ty);
}
}
}
} int main(){
while(scanf("%d%d",&n,&m)==2&&n){
cnt=0;
for(int i=0;i<n;i++){
scanf("%s",maz[i]);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
id[i][j]=-1;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(maz[i][j]!='*'&&id[i][j]==-1){
bfs(i,j);
}
}
} printf("%d\n",cnt);
}
return 0;
}
HDU 1241 Oil Deposits bfs 难度:0的更多相关文章
- HDU 1241 - Oil Deposits - [BFS]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 题意: 求某块平面上,连通块的数量.一个油田格子若周围八个方向也有一个油田格子,则认为两者相连通 ...
- HDU 1241 Oil Deposits(石油储藏)
HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Probl ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- DFS(连通块) HDU 1241 Oil Deposits
题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 1241 Oil Deposits (DFS/BFS)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
随机推荐
- Wormholes---poj3259(最短路 spfa 判断负环 模板)
题目链接:http://poj.org/problem?id=3259 题意是问是否能通过虫洞回到过去: 虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts. 我们把虫洞看成是一条负权路,问 ...
- Python开发【数据结构】:基础
数据结构 什么是数据结构? 简单来说,数据结构就是设计数据以何种方式组织并存储在计算机中. 比如:列表.集合与字典等都是一种数据结构 N.Wirth: “程序=数据结构+算法” 列表 列表:在其他编程 ...
- Portugal 2 1 minute has Pipansihuan Germany and USA tacit or kick the ball
C Luo assists last moment so that Portugal "back to life", but with just two games to allo ...
- SpringBoot开启缓存注解
https://blog.csdn.net/sanjay_f/article/details/47372967 https://www.cnblogs.com/lic309/p/4072848.htm ...
- PHP生成唯一RequestID类
https://blog.csdn.net/fdipzone/article/details/79939431 本文介绍PHP生成唯一RequestID类,使用session_create_id()与 ...
- HDU5023:A Corrupt Mayor's Performance Art(线段树区域更新+二进制)
http://acm.hdu.edu.cn/showproblem.php?pid=5023 Problem Description Corrupt governors always find way ...
- PAT 1056 Mice and Rice[难][不理解]
1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...
- html编码常见的有utf-8和gb2312编码等,应该如何判断选择?
html如何选择编码,常见utf-8和gb2312编码如何判断选择 一.首先了解目前国内中文网页常用编码是utf-8 还是gb2313. 比如: 百度搜索 网页使用utf-8 腾讯新闻 网页使用utf ...
- NiFi REST API 的使用
一.概述 为方便用户使用 NiFi 进行二次开发,NiFi 为开发者提供了 NIFI REST API. 关于 API 的详细介绍,请参见官网 NIFI REST API.这里仅给出一些注意的小细节. ...
- U盘安装window系统
U盘安装window系统: 1. 制作系统启动U盘,推荐使用老毛桃. 2. 电脑上插入U盘,启动系统,选择U盘启动. 3. 进入老毛桃选择界面,选择生成PE系统.推荐win8,之前在一个戴尔电脑上使用 ...