Hdu1241 Oil Deposits (DFS)
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
1
2
2
#include <bits/stdc++.h>
using namespace std;
char a[][];
int n,m,res;
int dx[]={,-,,};
int dy[]={,,,-};
void dfs(int x,int y)
{
a[x][y]='*';
for(int i=-;i<=;i++){
for(int j=-;j<=;j++){
int nx=x+i,ny=y+j;
if(nx>=&&nx<n&&ny>=&&ny<m&&a[nx][ny]=='@'){
dfs(nx,ny);
}
}
}
return ;
}
void solve()
{
res=;
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(a[i][j]=='@'){
dfs(i,j);
res++;
}
}
}
}
int main() {
while(cin>>n>>m&&(n&&m)){
for(int i=;i<n;i++){
for(int j=;j<m;j++){
cin>>a[i][j];
}
}
res=;
solve();
cout<<res<<endl;
}
return ;
}
Hdu1241 Oil Deposits (DFS)的更多相关文章
- HDU-1241 Oil Deposits (DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU1241 Oil Deposits —— DFS求连通块
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- Oil Deposits(dfs)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- hdu1241 Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- UVa572 Oil Deposits DFS求连通块
技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...
- HDU 1241 Oil Deposits (DFS/BFS)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
随机推荐
- Unity游戏推送技术
https://www.cnblogs.com/wuzhang/p/wuzhang20150401.html https://www.cnblogs.com/yangwujun/p/5789969.h ...
- [hive] hive 内部表和外部表
1.内部表 hive (test1)> create table com_inner_person(id int,name string,age int,ctime timestamp) row ...
- python列表的切片操作允许索引超出范围
其余的不说,列表切片操作允许索引超出范围:
- sip协议中文讲解
https://blog.csdn.net/qiuchangyong/article/details/50748854
- 算法-KMP
KMP算法的作用在于在一个主串中查找一个主串. 传统查找子串的方法是一个字符一个字符的比较,代码如下: public static int notKMP(String main,String sub) ...
- 死锁的原因及解决办法RLock递归锁
死锁 说到死锁,可以讲一个科学家吃面的问题: 有几个科学家在一张桌子旁,桌子上只有一把筷子和一碗面,我们将面和筷子都加锁.这是可能会导致一个科学家抢到面,另一个科学家抢到筷子,这是就全部阻塞了,这就是 ...
- vue2 在mounted函数无法获取prop中的变量的解决方法
props: { example: { type: Object, default() { }, }, }, watch: { example: function(newVal,oldVal){ // ...
- Integer 的 valueOf 方法 与 常量池(对 String Pool 的部分理解)
举例: public class Test { @org.junit.Test public void intTest() { Integer t1 = 128; Integer t2 = 127; ...
- react-redux简单实用
首先了解一个过程,redux 肯定是通过在组件中出发一个方法(事件),我们可以实现一个简单的例子播放和停止播放(写到这今日心情不好,下次继续) redux需要安装 以下依赖:cnpm install ...
- Unified Temporal and Spatial Calibration for Multi-Sensor Systems
下载链接:点击 为了提高机器人状态估计的准确性和鲁棒性,越来越多的应用依赖于来自多个互补传感器的数据. 为了在传感器融合中获得最佳性能,这些不同的传感器必须在空间上和时间上相互对准.为此,已经开发了许 ...