Uva 572 Oil Deposits
来源:互联网 发布:自由游戏程序员 编辑:程序博客网 时间:2024/05/21 16:38
Oil Deposits
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu
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 containingm and n, the number of rows and columns in the grid, separated by a single space. Ifm = 0 it signals the end of the input; otherwise and. Following this arem 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<iostream>#include<string.h>using namespace std;char cnt[101][101];int vis[101][101];int count,m,n;void dfs(int x,int y , int id){ for(int i=-1; i<=1; i++) for(int j=-1; j<=1; j++) { int tx=x+i; int ty=y+j; if(tx>=0&&ty>=0&&tx<m&&ty<n&&cnt[tx][ty]=='@'&&!vis[tx][ty]) { vis[x][y]=id; dfs(tx,ty,id); } } return ;}int main(){ while(cin>>m>>n,m) { memset(vis,0,sizeof(vis)); for(int i=0; i<m; i++) for(int j=0; j<n; j++) cin>>cnt[i][j]; int count=0; for(int k=0; k<m; k++) for(int q=0; q<n; q++) { if(!vis[k][q]&&cnt[k][q]=='@') { vis[k][q]=++count; dfs(k,q,count); } } cout<<count<<endl; } return 0;}
0 0
- uva 572 - Oil Deposits
- uva 572 - Oil Deposits
- uva 572 - Oil Deposits
- uva-572-Oil Deposits
- UVa 572 - Oil Deposits
- UVa 572 - Oil Deposits
- UVa 572 - Oil Deposits
- uva 572Oil Deposits
- UVa 572Oil Deposits
- UVa 572 - Oil Deposits
- UVa 572: Oil Deposits
- uva 572 Oil Deposits
- UVa 572 - Oil Deposits
- uva 572 oil Deposits
- uva 572 - Oil Deposits
- uva 572 - Oil Deposits
- UVa 572 - Oil Deposits
- UVA 572 Oil Deposits
- 软件外包之行情
- HashMap
- 今天是个比较特殊的日子——再次受到创伤
- 交叉编译资料1
- 2015年阿里巴巴实习面试经验
- Uva 572 Oil Deposits
- hihoCoder 1049 : 后序遍历
- LeetCode 202:Happy Number
- [1]Cocos2d-x之建立项目
- iOS UIButton的第四种状态(选中高亮)
- kindle资源网址
- expdp导出遇到ORA-39064: 无法写入日志文件
- android布局的id和+id的区别
- 对于理解操作系统的产生有帮助的文章