HDU-1241 Oil Deposits (DFS)

时间:2022-09-18 21:23:09

Oil Deposits

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

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

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

0
1
2
2

Source

Mid-Central USA 1997
 #include<stdio.h>
#include<string.h>
char f[][]={,,,,,,-,,-,,-,-,,-,,-};//定义方向数组,8个方向,多了个折线方向。
int n,m;
char map[][];
void dfs(int x,int y)
{
int x1,y1,i;
for(i=;i<;i++)
{
x1=x+f[i][];
y1=y+f[i][];
if(x1>=n||y1>=m||x1<||y1<||map[x1][y1]!='@')
continue;
map[x1][y1]='*';//把访问过的@变成*,下次就不会再访问。
dfs(x1,y1);
}
}
int main()
{
int i,j,s;
while(~scanf("%d%d",&n,&m)&&n!=&&m!=)
{
s=;
for(i=;i<n;i++)
scanf("%s",map[i]);
for(i=;i<n;i++)
for(j=;j<m;j++)
if(map[i][j]=='@')
{
map[i][j]='*';
s++;
dfs(i,j);
}
printf("%d\n",s);
}
return ;
}
 

HDU-1241 Oil Deposits (DFS)的更多相关文章

  1. HDOJ&lpar;HDU&rpar;&period;1241 Oil Deposits&lpar;DFS&rpar;

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  2. HDU 1241 Oil Deposits DFS&lpar;深度优先搜索&rpar; 和 BFS(广度优先搜索)

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  3. HDU 1241 Oil Deposits &lpar;DFS&sol;BFS&rpar;

    Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  4. HDU 1241 Oil Deposits &lpar;DFS or BFS&rpar;

    链接 : Here! 思路 : 搜索判断连通块个数, 所以 $DFS$ 或则 $BFS$ 都行喽...., 首先记录一下整个地图中所有$Oil$的个数, 然后遍历整个地图, 从油田开始搜索它所能连通多 ...

  5. HDU 1241 Oil Deposits DFS搜索题

    题目大意:给你一个m*n的矩阵,里面有两种符号,一种是 @ 表示这个位置有油田,另一种是 * 表示这个位置没有油田,现在规定相邻的任意块油田只算一块油田,这里的相邻包括上下左右以及斜的的四个方向相邻的 ...

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

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

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

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

  8. DFS&lpar;连通块&rpar; HDU 1241 Oil Deposits

    题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...

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

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

  10. hdu 1241&colon;Oil Deposits(DFS)

    Oil Deposits Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

随机推荐

  1. 去除html的&amp&semi;nbsp&semi;标签

    // 去除html的 标签 String str = "  2016-09-02"; if (str.indexOf("\u00A0") != -1) { st ...

  2. sed 命令及shell的if语句的运用实例

    if [ -f /etc/syslog.conf ];     #判断文件是否存在thensystest=`sed -n  '/^auth.info/p' /etc/syslog.conf`;    ...

  3. Shell脚本——中继DHCP服务器自动部署

    详细说明参照: (四)跟我一起玩Linux网络服务:DHCP服务配置之中继代理 vm1的脚本是: #! /bin/bash HIPSEG="10.10.10" SIPSEG=&qu ...

  4. erlang ets表

    一.表遍历 通过ets:first/1获取表的第一个关键字,表中下一个关键字用ets:next/2得到,直到ets:next/2返回'$end_of_table' 当多几个进程并发访问ets表时,可以 ...

  5. PostMessage 向Windows窗口发送Alt组合键

    PostMessage 向Windows窗口发送Alt组合键 关于向Windows窗口发送Alt组合键的问题,这个真是经典问题啊,在网上找了一下,问的人N多,方法差不多, 但就是没有很好解决问题. 之 ...

  6. &lbrack;vue最新实战&rsqb; gank客户端(vue2 &plus; vue-router2 &plus; vuex &plus;webpace &plus; es6)新手福利,干货多多

    vue-meizi 本项目是基于vue2最新实战项目,是适合新手进阶的绝佳教程.代码简单易懂,注释多多.实现了移动端使用最多的 无限滚动,图片加载,左右滑动,等待.先发布预览版本,后面更多更全的功能和 ...

  7. display&colon;box和display&colon;flex填坑之路

    背景分析:最近做移动端项目时,遇到一个常见的需求: 可以滑动的导航,如下图 虽然是很常见的一个布局,但在移动端没有做过,想当然的写下以下的样式,简单描述下: 父元素 width:100%: overf ...

  8. LeetCode之旅(16)-Climbing Stairs

    题目描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either ...

  9. 【RL-TCPnet网络教程】第35章&Tab; FTP文件传输协议基础知识

    第35章      FTP文件传输协议基础知识 本章节为大家讲解FTP(File Transfer Protocol,文件传输协议)的基础知识,方便后面章节的实战操作. (本章的知识点主要整理自网络) ...

  10. ThinkPHP5&period;0 开发手册

    ThinkPHP5.0开发手册地址 https://www.kancloud.cn/manual/thinkphp5/118003 此博文仅仅作为个人笔记存储,没有广告,宣传的意图