Oil Deposits
来源:互联网 发布:快播软件 编辑:程序博客网 时间:2024/06/04 19:57
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.
1 1*3 5*@*@***@***@*@*1 8@@****@*5 5 ****@*@@*@*@**@@@@*@@@**@0 0
0122
题意:简单的求@的连通块的个数。然后相邻的算8个方向的,上下左右+4个斜角。
#include <cstdio>#include <queue>#include <cstring>using namespace std;const int MAXN=100+7;const int inf=1e9;int n,m;int sx,sy;char tu[MAXN][MAXN];int vis[MAXN][MAXN];int dx[8]= {0,0,1,-1,-1,-1,1,1};int dy[8]= {1,-1,0,0,-1,1,-1,1};void dfs(int x,int y,int cnt){ vis[x][y]=cnt; for(int i = 0; i < 8; ++i) { int nx = x + dx[i]; int ny = y + dy[i]; if(nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny] && tu[nx][ny] == '@') { dfs(nx, ny, cnt); } }}int main(){ while(~scanf("%d%d",&n,&m)&&n) { memset(vis,0,sizeof(vis)); for(int i = 0 ; i < n ; ++i) { scanf("%s",tu[i]); } int cnt=0; for(int i = 0 ; i < n ; ++i) for(int j = 0; j < m ; ++j) { if(tu[i][j] == '@' && !vis[i][j])dfs(i,j,++cnt); } printf("%d\n",cnt); } return 0;}
阅读全文
0 0
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- Oil Deposits
- oil deposits
- Oil Deposits
- Oil Deposits
- HRBUST 2326 Blind Father "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛
- js的事件冒泡和事件捕获
- Python初遇问题5.16
- Appium 切换Webview模式,页面还停留在原来页面的问题
- Bootstrap栅格系统的精妙之处
- Oil Deposits
- 工科数学分析大作业(三) 傅里叶级数
- SURF特征提取分析
- Linux Centos 6.6安装Mysql
- url打开app
- Android 开发—— 小工具,大效率
- acm 香港网络赛D题
- Spark日志清洗一般流程(Python版)
- 网页布局