#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char map[][]; int dir[][]={, , , , -, , , -, , , , -, -, , -, -};
int n, m;
int ans; bool judge(int x, int y){
if(x< || x>n || y< || y>m) return false;
return true;
} void dfs(int x, int y, bool flag){ if(map[x][y]=='@'){
map[x][y]='*';
++ans;
for(int i=; i<; ++i){
int xx=x+dir[i][], yy=y+dir[i][];
if(judge(xx, yy) && map[xx][yy]=='@'){
--ans;
dfs(xx, yy, );
}
}
if(flag) return;//flag==1表明没有将油田搜索完毕
} for(int i=; i<; ++i){
int xx=x+dir[i][], yy=y+dir[i][];
if(judge(xx, yy) && map[xx][yy]!='#'){
if(map[xx][yy]=='*')
map[xx][yy]='#';
dfs(xx, yy, );
}
}
} int main(){
while(cin>>n>>m && (n||m)){
for(int i=; i<=n; ++i)
cin>>(map[i]+);
ans=;
dfs(, , );
cout<<ans<<endl;
}
return ;
}

hdu 1241 Oil Deposits (一次dfs搞定有某有)的更多相关文章

  1. HDU 1241 Oil Deposits(经典DFS)

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

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

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

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

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

  4. HDOJ(HDU).1241 Oil Deposits(DFS)

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

  5. DFS(连通块) HDU 1241 Oil Deposits

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

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

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

  7. hdu 1241:Oil Deposits(DFS)

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

  8. HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)

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

  9. HDU 1241 Oil Deposits (DFS/BFS)

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

随机推荐

  1. bfc+css

    CSS BFC的定义 是 W3C CSS 2.1 规范中的一个概念,它决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用.在创建了 Block Formatting Context 的元素 ...

  2. [XAF] How to represent an enumeration property via a drop-down box with check boxes

    https://www.devexpress.com/Support/Center/Example/Details/E689

  3. .NET环境下导出Excel表格的两种方式和导入两种类型的Excel表格

    一.导出Excel表格的两种方式,其中两种方式指的是导出XML数据类型的Excel(即保存的时候可以只需要修改扩展名为.xls)和真正的Excel这两种. using System; using Sy ...

  4. Export GridView Data to Excel. 从GridView导出数据到Excel的奇怪问题解析

    GridView导出函数内容如下 string attachment = "attachment; filename=Contacts.xls";            Respo ...

  5. XMPP即时通信(基础)

      使用第三方框架 XMPPFramework   #import "ViewController.h" #import "XMPPFramework.h" @ ...

  6. STL练习题续

    //zjnu 1399 //sort 数组可用//vector sort(vector) #include<iostream> #include<algorithm> usin ...

  7. 基于EasyUi ComBotree树修改 父节点选择问题

    本人在使用 Easy UI 期间发现了一个不太适合项目的bug,可能也不算bug把 . 毕竟不同项目背景 取舍不同. 我在做网元树选择的时候  发现当选取父节点后,子节点都会被选择  返回  .但是如 ...

  8. 离线安装eclipse的svn插件

    原文:http://blog.sina.com.cn/s/blog_8e037f440101ebmz.html 连接不到外网情况下,在eclipse中安装svn插件. 两种方法: 首先下载安装到ecl ...

  9. HTML5-链接

    链接:外部,图片,内部 <!DOCTYPE html> <html> <head lang="en"> <meta charset=&qu ...

  10. Dubbo框架选型

    一.为什么会是dubbo 1.Dubbo是一个分布式服务框架,提供RPC(远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议.) 远程服务调用方案,以及SOA ...