HDU 1241 Oil Deposits
来源:互联网 发布:sql语句distinct缺点 编辑:程序博客网 时间:2024/05/22 05:03
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 <string.h>#include <iostream>using namespace std;char map[105][105];int n,m,ans,i,j;int xx[8]={-1,-1,0,1,1,1,0,-1}; int yy[8]={0,1,1,1,0,-1,-1,-1}; void dfs(int x,int y){ map[x][y]='*'; for(int i=0;i<8;i++) { int c=x+xx[i],b=y+yy[i]; if(c >= n || b >= m || c < 0 || b < 0 ) continue; if(map[c][b]=='@') { dfs(c,b); } }}/*void dfs(int x,int y){ map[x][y] = '*'; for(int i=0;i<8;i++) { int fx = x + xx[i]; int fy = y + yy[i]; if( fx < 0 || fy < 0 || fx >= n || fy >= m || map[fx][fy] == '*' ) continue; dfs(fx,fy); }}*/int main(){ while(~scanf("%d %d",&n,&m),n||m) { ans=0; for(i=0;i<n;i++) { cin >> map[i]; } for(i=0;i<n;i++) for(j=0;j<m;j++) { if(map[i][j]=='@') { dfs(i,j); ans++; } } printf("%d\n",ans); } return 33;}
0 0
- HDU 1241Oil Deposits
- HDU---1241Oil Deposits
- Hdu 1241 Oil Deposits
- Hdu 1241 - Oil Deposits
- HDU-1241:Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu - 1241 - Oil Deposits
- HDU-1241Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- HDU 1241 Oil Deposits
- hdu 1241 Oil Deposits
- hdu 1241 Oil Deposits
- HDU 1241 Oil Deposits
- hdu-1241-Oil Deposits
- hdu 1241 Oil Deposits
- Display tag library 1.2
- delphi 中的 cxgrid运用当中 EXCEL合并形式
- 《数学之美(第二版)》(四)
- 中国特色的流程需求
- Step into Kotlin - 12 - Object 与枚举
- HDU 1241 Oil Deposits
- Quick小白书系列(二)创建自己的项目并做点有意思的小内容
- 悟空学Linux专栏----第27篇
- 未完的歌
- EASY_SIZE使用
- Redis各种数据结构内存占用测试
- jquery checkbox 显示checked undefined
- 虚拟机和宿主机实现共享文件夹,粘贴板和双向拖放
- struts2学习笔记(7)---数据验证之validateXxx()方法