Oil Deposits

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 4   Accepted Submission(s) : 3

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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

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

*

*@*@*
**@**
*@*@* @@****@* ****@
*@@*@
*@**@
@@@*@
@@**@

Sample Output

0
1
2
2

Source

Mid-Central USA 1997

 
  这是道经典dfs搜索题,难度属于入门级,没有太难的地方。
  下面是代码:
 #include <iostream>
using namespace std;
char a[][];
int dx[] = {,,,,,-,-,-};
int dy[] = {,,,-,-,-,,};
int m,n;
void dfs(int x,int y) //将(x,y)坐标有联系的所有坐标都标记为 *
{
a[x][y]='*';
for(int i=;i<;i++){
int nx = x+dx[i];
int ny = y+dy[i];
if( nx< || ny< || nx>m || ny>n) //如果越界
continue;
if(a[nx][ny]!='@') //如果这样走的下一步不是 @
continue;
dfs( nx , ny );
}
}
int main()
{
while(cin>>m>>n,m!=){
int _count=;
for(int i=;i<=m;i++)
for(int j=;j<=n;j++)
cin>>a[i][j];
for(int i=;i<=m;i++)
for(int j=;j<=n;j++){
if(a[i][j]=='@'){
_count++;
dfs(i,j);
}
}
cout<<_count<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 1241:Oil Deposits(DFS)的更多相关文章

  1. HDU 1241 Oil Deposits (DFS)

    题目链接:Oil Deposits 解析:问有多少个"@"块.当中每一个块内的各个"@"至少通过八个方向之中的一个相邻. 直接从"@"的地方 ...

  2. hdu 1241 Oil Deposits(DFS求连通块)

    HDU 1241  Oil Deposits L -DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & ...

  3. HDU 1241 Oil Deposits(石油储藏)

    HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)   Probl ...

  4. HDU 1241 Oil Deposits --- 入门DFS

    HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...

  5. hdu 1241 Oil Deposits (简单搜索)

    题目:   The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...

  6. HDOJ/HDU 1241 Oil Deposits(经典DFS)

    Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...

  7. HDU 1241 Oil Deposits【DFS】

    解题思路:第一道DFS的题目--- 参看了紫书和网上的题解-- 在找到一块油田@的时候,往它的八个方向找,直到在能找到的范围内没有油田结束这次搜索 可以模拟一次DFS,比如说样例 在i=0,j=1时, ...

  8. HDU 1241 Oil Deposits(经典DFS)

    嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 很经典的一道dfs,但是注意每次查到一个@之后,都要把它变成“ * ”,然后继续dfs ...

  9. poj1562 Oil Deposits(DFS)

    题目链接 http://poj.org/problem?id=1562 题意 输入一个m行n列的棋盘,棋盘上每个位置为'*'或者'@',求'@'的连通块有几个(连通为8连通,即上下左右,两条对角线). ...

随机推荐

  1. WebSphere SSLC0008E 无法初始化 SSL 连接。未授权访问被拒绝,或者安全性设置已到期 解决方法

    昨天安装websphere服务器中间件,安装完毕之后,安装验证如下: 猜测是SSL协议版本过低的问题,于是打开IE高级设置: 勾线之后,启动管理控制台: 成功启动web界面如下: 登陆试试:

  2. win7打开网页老是提示下载网页解决办法

    方法:我的系统是windows 7 旗舰版, 解决方法可以自己手动去修复,方法是进入命令窗口. 开始--运行--cmd--sfc.exe--sfc/scannow   修复一下!

  3. 转:this的用法

    this指针的含义及其用法: 1. this指针是一个隐含于每一个成员函数中的特殊指针.它指向正在被该成员函数操作的那个对象.2. 当对一个对象调用成员函数时,编译程序先将对象的地址赋给this指针, ...

  4. sql 联合查询并更新

    update sales set sales.adminId = t.adminIdfrom (select a.adminId,a.realName from sales ,admin_admini ...

  5. 百度地图代码API

    百度地图代码API: http://api.map.baidu.com/lbsapi/creatmap/index.html

  6. hdu.5203.Rikka with wood sticks(数学推导:一条长度为L的线段经分割后可以构成几种三角形)

    Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  7. HNU 12845 Ballot Analyzing Device

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12845&courseid=270 解题报告:有m个认给 ...

  8. 通过rails console执行sql语句

    $ RAILS_ENV=production bundle exec rails c irb(main):008:0> r = ActiveRecord::Base.connection.exe ...

  9. linux tar文件解压

    把常用的tar解压命令总结下,当作备忘: tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个, ...

  10. 每天一个脚本解析day1==》《service xxxxx status》之service脚本解析

    vim    /sbin/service #!/bin/sh . /etc/init.d/functions #读取环境变量. VERSION="$(basename $0) ver. 0. ...