HDU 1241 Oil Deposits DFS求连通块
来源:互联网 发布:sql server时间戳转换 编辑:程序博客网 时间:2024/06/10 04:36
HDU 1241 Oil Deposits DFS求连通块
传送门
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.
题目意思:求所有独立的@的块有多少个,@周围的(八个方向)算一个块。
dfs计数就好
//// main.cpp// whr_bfs//// Created by 41 on 17/8/7.// Copyright (c) 2017年 henuwhr. All rights reserved.//#include <iostream>#include <cstdio>#include <algorithm>#include <queue>#include <map>#include <cstring>using namespace std;int n,m;char mp[105][105];int res = 0;int dir[][2]={1,0,1,-1,0,-1,-1,-1,-1,0,-1,1,0,1,1,1};void dfs(int x,int y){ int i,xx,yy; mp[x][y] = '*'; for(i = 0 ;i<8;i++){ xx = x+dir[i][0]; yy = y+dir[i][1]; if(xx<0||yy<0||xx>=m||yy>=n) continue; if(mp[xx][yy]=='@') dfs(xx,yy); }}int main(int argc, const char * argv[]) { while(cin>>m>>n,m+n){ res = 0; memset(mp,0,sizeof mp); for(int i = 0;i<m;i++){ cin>>mp[i]; } for(int i = 0 ;i<m;i++){ for(int j = 0 ;j<n;j++){ if(mp[i][j]=='@'){ dfs(i,j); res++; } } } cout << res <<endl; } return 0;}
- HDU 1241 Oil Deposits DFS求连通块
- UVa 572 Oil Deposits(DFS求8连通块)
- UVA572 POJ1562 oil deposits(DFS求连通块问题)
- UVA 572 Oil Deposits dfs求连通块
- UVa - 572 - Oil Deposits(dfs求连通块)
- Uva572 Oil Deposits 【dfs求连通块】【例题6-12】
- HDU1241 Oil Deposits —— DFS求连通块
- DFS:POJ1562-Oil Deposits(求连通块个数)
- Uva 572 Oil Deposits 油田 (DFS求连通块)
- HDOJ 1241 Oil Deposits【最大连通块 dfs】
- poj 1562 ,hdu 1241 Oil Deposits dfs,bfs 求连通分支数
- hdu 1241 Oil Deposits (连通块的个数)
- HDU 1241 Oil Deposits(连通块的数量)
- 6.4.1 用DFS求连通块 UVA 572 Oil Deposits DFS水题
- UVA572 Oil Deposits(DFS求连通块(floodfill 种子填充))
- 经典第六章 例题 6-12 UVA 572 Oil Deposits(用DFS求连通块)
- 用DFS求连通块(油田Oil Deposits,UVa 572)
- 例题6-12 UVA572 Oil Deposits 基础dfs求连通块
- 守护进程的实现
- HttpClient
- bean依赖注入错误:Error creating bean with name 'itemService': Injection of autowired dependencies failed
- mysql数据类型
- 在Unity3D中使用Visual Studio调试shader
- HDU 1241 Oil Deposits DFS求连通块
- 刚培训出来的我,java博客第一天,努力成为大牛
- Class对象-单例
- oracle(二)
- 生产者和消费者问题
- 高斯消元
- 训练日记-8
- 3342数据结构实验之二叉树三:统计叶子数
- Ubuntu16.04 配置java环境