bfs hdu 1241
来源:互联网 发布:mac文件夹属性隐藏 编辑:程序博客网 时间:2024/06/06 03:32
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35239 Accepted Submission(s): 20453
Problem 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
0122#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;char Map[1005][1005];int vis[1005][1005];struct note{int x,y;};int n,m;int dx[8]={1,1,-1,-1,1,-1,0,0};int dy[8]={1,-1,1,-1,0,0,1,-1};int bfs(int i, int j){note u;u.x = i,u.y = j;for(int i = 0; i < 8;i++){note v;v.x=u.x+dx[i];v.y=u.y+dy[i];if(vis[v.x][v.y] == 0&&Map[v.x][v.y] == '@'&&v.x>=0&&v.y>=0&&v.x<n&&v.y<m){vis[v.x][v.y] = 1;//Map[v.x][v.y]='*' bfs(v.x,v.y);}}}int main(){while(~scanf("%d %d",&n,&m)){int step = 0;memset(vis,0,sizeof(vis));if(n == 0&&m == 0)break;for(int i = 0; i < n; i++){scanf("%s",Map[i]);}for(int i = 0; i < n; i++){for(int j = 0; j < m;j++){if(vis[i][j] == 0&&Map[i][j] == '@'){vis[i][j] = 1;bfs(i,j);step++;}}}printf("%d\n",step);}}
阅读全文
0 0
- hdu 1241 BFS
- [BFS] HDU 1241
- bfs hdu 1241
- hdu 1241 bfs or dfs
- hdu 1241 Oil Deposits - bfs
- hdu 1241Oil Deposits(BFS)
- hdu 1241 Oil Deposits (BFS)
- HDU 1241 BFS-Oil Deposits
- 【BFS】HDU 1241 Oil Deposits
- HDU 1241 Oil Deposits <BFS>
- HDU bfs
- POJ 1562/HDU 1241 Oil Deposits(BFS)
- hdu 1241 Oil Deposits_dfs or bfs
- HDU-#1241 Oil Deposits(BFS & DFS)
- HDU 1241 Oil Deposits[dfs || bfs]
- HDU 1241 Oil Deposits (DFS/BFS)
- L - Oil Deposits HDU 1241 基础BFS
- HDU 1241 Oil Deposits (DFS+BFS)
- 2017年第26届上海国际连锁加盟展览会会刊(参展商名录)
- PHP字符串的表示方法
- Android多线程的四种方式
- spring mvc集成mybatis进行数据库访问
- mybatis 缓存
- bfs hdu 1241
- CentOS 编译vim no terminal library found
- Log4j2之RollingFileAppender学习笔记
- rails中active_record的delete和destroy方法
- 如何拍出更好看的照片,那是有技巧的
- sparkmllib (1)
- appium使用教程
- 【Java】【注解】自定义注解
- 通过六个题目彻底掌握String笔试面试题