#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. 8.4.3 Glide

    1). 导入库 dependencies { compile 'com.github.bumptech.glide:glide:3.5.2' compile 'com.android.support: ...

  2. linux中sed的用法【转】

    sed命令行格式为:         sed [-nefri]  ‘command’  输入文本/文件 常用选项:        -n∶取消默认的输出,使用安静(silent)模式.在一般 sed 的 ...

  3. 声笔码7.00版现已进入Beta测试阶段

    声笔码7.00版现已进入Beta测试阶段,有兴趣的朋友可以试试,欢迎多提宝贵意见. 由于论坛附件限制了1M的大小所以无法上传,需要的朋友可加入声笔系列码群(QQ群号:445906697),到共享文件夹 ...

  4. getIdentifier()获取资源Id

    工作需要使用getIdentifier()方法可以方便的获各应用包下的指定资源ID.主要有两种方法:(1)方式一Resources resources = context.getResources() ...

  5. centos6 一个vlan配置多ip地址

    添加vlan [root@localhost network-scripts]# vconfig add eth1 109 配置文件,此处配置了vlan109使用子接口进行多ip配置: [root@l ...

  6. centos 清理内存缓存

    读写文件时,Linux内核为了提高读写效率与速度,会将文件在内存中进行缓存,这就是Cache Memory(缓存内存).即使程序运行结束后,Cache Memory也不会自动释放.这就会导致程序频繁读 ...

  7. winform 子报表数据源赋值

    this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource(&qu ...

  8. 【异常】VS中运行HTTP 无法注册URL

    参考资料 http://www.java123.net/detail/view-449670.html http://www.cnblogs.com/jiewei915/archive/2010/06 ...

  9. Jquery Mobile 小结

    第一次做一个移动站点,当时纠结选Jquery Mobile还是Zepto,Zepto相对于JM更加轻巧,语法上面也很相似,但考虑到时间问题和JM自带了很多组件(Bootstrap惯出来的),还是选择了 ...

  10. JavaScript函数编程-Ramdajs

    在JavaScript语言世界,函数是第一等公民.JavaScript函数是继承自Function的对象,函数能作另一个函数的参数或者返回值使用,这便形成了我们常说的高阶函数(或称函数对象).这就构成 ...