Oil Deposit
- 题目描述:
-
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.
- 输入:
-
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.
- 输出:
-
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.
- 样例输入:
-
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
- 样例输出:
-
0
1
2
2
#include<iostream>
#include<stdio.h>
#include<queue>
using namespace std;
char maze[][];
bool mark[][];
int go[][]={
,,
-,,
,,
,-,
-,-,
,,
-,,
,-
};
int m,n;
void dfs(int x,int y){
for (int i=;i<;i++){
int nx=x+go[i][];
int ny=y+go[i][];
if (nx<||nx>=m||ny<||ny>=n) continue;
if (maze[nx][ny]=='*' || mark[nx][ny]==true) continue;
mark[nx][ny]=true;
dfs(nx,ny);
}
return;
} int main (){ while (cin>>m>>n && !(m==&&n==)){
for (int i=;i<m;i++){
//getchar();
for (int j=;j<n;j++){
//scanf("%c",maze[i][j]);
cin>>maze[i][j];
mark[i][j]=false;
}
} int ans=;
for (int i=;i<m;i++){
for (int j=;j<n;j++){
if (maze[i][j]=='*') continue;
if (mark[i][j]==true) continue;
dfs(i,j);
ans++;
}
}
cout<<ans<<endl;
} return ;
}
这种将相邻的点合成块的算法有一个专有名词,floodfill
Oil Deposit的更多相关文章
- 题目1460:Oil Deposit(递归遍历图)
题目链接:http://ac.jobdu.com/problem.php?pid=1460 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 九度oj 题目1460:Oil Deposit
题目描述: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...
- Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Oil Deposits(dfs)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 2016HUAS暑假集训训练题 G - Oil Deposits
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- uva 572 oil deposits——yhx
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil d ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- hdu1241 Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) ...
- 杭电1241 Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ...
随机推荐
- C语言多种方法求解字符串编辑距离问题的代码
把做工程过程经常用的内容记录起来,如下内容段是关于C语言多种方法求解字符串编辑距离问题的内容. { if(xbeg > xend) { if(ybeg > yend) return 0; ...
- F1赛道 - Bahrain International Circuit | 巴林国际赛道
刚看完F1巴林站比赛,23点到1点,整整两个小时,比赛相当精彩. 从排位赛结果看,法拉利似乎肯定包揽1-2名,可惜天公不作美,今晚风大.沙多:vettel自己失误,鼻翼掉了,还在被汉密尔顿超车的时候自 ...
- 持续集成CI/CD
Gitlab+kubernetes+docker+jenkins+harbor搭建持续交付系统 http://blog.chenmiao.cf/2016/12/28/gitlab+kubernetes ...
- Linux之nginx入门
nginx入门 详见可参考:https://www.cnblogs.com/tiger666/p/10239307.html?tdsourcetag=s_pctim_aiomsg 1. 常用的WEB框 ...
- hdu6396(思维+输入挂)
Swordsman Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accept ...
- 用servlet验证密码2
function createXMLHttpRequest() { var XMLHttpRequest1; if (window.XMLHttpRequest) { XMLHttpRequest_t ...
- Tsinghua 2018 DSA PA2简要题解
反正没时间写,先把简要题解(嘴巴A题)都给他写了记录一下. upd:任务倒是完成了,我也自闭了. CST2018 2-1 Meteorites: 乘法版的石子合并,堆 + 高精度. 写起来有点烦貌似. ...
- laravel的测试工具debug安装:
在项目根目录执行: composer require barryvdh/laravel-debugbar --dev
- Linux c使用gumbo库解析页面表单信息(二)
一.如何在程序当中使用gumbo? 要想在代码中使用gumbo,仅仅包含gumbo头文件是不够的,必须在编译程序的时候加上-lgumbo选项,编译程序才会链接到gumbo库上面. 这是我编译gumbo ...
- Romaji (CodeForces - 1008A )
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphab ...