HDU——1241 Oil Deposits
来源:互联网 发布:ubuntu自动获取ip地址 编辑:程序博客网 时间:2024/06/03 14:57
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18731 Accepted Submission(s): 10798
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简单深搜题,遍历8个方向,统计个数#include<stdio.h>#include<iostream>#include<queue>#include<algorithm>#include<string.h>#include<string>#define M(i,m,n) for(int i=m;i<n;i++)#define N(i,m,n) for(int i=m-1;i>=0;i--)#define L(n,m) memset(n,m,sizeof(n));using namespace std;char a[122][122];int b[122][122],s[8][2]= {{-1,0},{1,0},{0,1},{0,-1},{1,-1},{-1,1},{1,1},{-1,-1}},sum,n,m;void dfs(int x,int y){ b[x][y]=1; for(int i=0;i<8;i++) { int t1=x+s[i][0]; int t2=y+s[i][1]; if(t1>=0&&t1<n&&t2>=0&&t2<m&&a[t1][t2]=='@'&&!b[t1][t2]) { b[t1][t2]=1; dfs(t1,t2); } } return ;}int main(){ while(~scanf("%d%d",&n,&m)) { L(b,0) if(m==0&&n==0) break; sum=0; M(i,0,n) M(j,0,m) cin>>a[i][j]; M(i,0,n) M(j,0,m) if(a[i][j]=='@'&&!b[i][j]) { sum++; dfs(i,j); } cout<<sum<<endl; }}
0 0
- HDU——1241 Oil Deposits
- 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
- android :gravity 与android: layout_gravity的区别
- js方式的页面跳转
- DrawCache
- MybatisUtil示例
- CSS之float详解
- HDU——1241 Oil Deposits
- Jenkins构建iOS持续集成环境(一)
- edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性详解
- ASP.NET温故而知新学习系列之网站安全技术—加强页面间传值的安全性Convert.ToBase64String(三)
- 牵手泰隆银行,DevSuite助力IT项目研发管理新飞跃
- 控件切圆角与画边框
- 解读《关于促进大数据发展的行动纲要》
- leetcode Binary Search Tree Iterator
- overflow:hidden