[ACM]Uva572-Oil Deposits-DFS应用
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn = 100 + 5;
char piece[maxn][maxn];
int n,m,idx[maxn][maxn];
void dfs(int r, int c, int id)
{
if(r<0 || r>=m || c<0 || c>=n) return;
if(idx[r][c] > 0 || piece[r][c]!='@') return;
idx[r][c]=id;
for(int dr=-1; dr<=1;dr++)//dfs式探索
for(int dc=-1;dc<=1;dc++)
if(dr!=0 || dc!=0) dfs(r+dr, c+dc, id);
}
int main(){
while(scanf("%d%d", &m, &n) == 2 && m && n)
{
for(int i=0;i<m;i++)
{
cin>>piece[i];
}
memset(idx, 0 ,sizeof(idx));
int cur=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(idx[i][j]==0 && piece[i][j] == '@')
dfs(i,j,++cur);
}
}
cout<<cur<<endl;
}
return 0;
}
[ACM]Uva572-Oil Deposits-DFS应用的更多相关文章
- UVa572 Oil Deposits DFS求连通块
技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...
- UVA572 Oil Deposits DFS求解
小白书上经典DFS题目. 1. 递归实现 // from: https://www.cnblogs.com/huaszjh/p/4686092.html #include <stdio.h> ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- Oil Deposits(dfs水)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...
- HDU1241 Oil Deposits —— DFS求连通块
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Othe ...
- Oil Deposits(dfs)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 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)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU_1241 Oil Deposits(DFS深搜)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
随机推荐
- python投票一致性指数(IVC)实现代码
毕业论文中用于计算联合国会员国间在联合国大会上的投票一致性(IVC) import pandas as pd import sqlite3 import networkx as nx import t ...
- vue2项目引入新版ant-design-vue报错问题
vue2项目引入3.2.14版ant-design-vue会报1600多个编译错误,纯属版本问题,但3.2.14版本卸载会出错,需要删除项目重建,重建后搜索依赖ant-design-vue-fixed ...
- node后台项目所需中间件梳理
0.nodemon 全局工具,监听项目文件变动,并自动重启项目 一.node内置模块 1.fs fs.readFile() 读取指定文件中的内容fs.writeFile() 向指定的文件中写入内容 ...
- prometheus 配置数据保留7天时间storage.tsdb.retention.time
1.修改配置如下: 默认24h添加配置:retention: 168h
- vue-多个卡片翻转动效
<van-grid :column-num="2" class="content" :border="false" > < ...
- 字节过滤流 --->对象流(存入对象的)----> ObjectOutputStream: 用法
前提:1).要有一个类 并创建这个类的对象2)要让类必须继承Serializable接口3)transient修饰的属性 值不参与序列化1创建字节输出节点流FileOutputStream fos = ...
- 第12组 Beta冲刺 (1/5)
1.1基本情况 ·队名:美少女战士 ·组长博客: https://www.cnblogs.com/yaningscnblogs/p/14016591.html ·作业博客:https://edu.cn ...
- oracle表名中带@什么意思,例如:select * from dim.dim_area_no@to_dw
转载自:https://zhidao.baidu.com/question/259154968.html @是调用数据库链接(database link)的意思. 数据库链接的作用是从a数据库到b数据 ...
- 量化交易基础-ICIR
IC - information coefficient r=1.5+a1+a2+...+a81 ai={-1,1}随机序列 ()收益序列 E(r)=1.5 期望 cov(r)=81 协方差 std( ...
- Docker安装(win10)
Docker安装 windows 首先开启Hyper-V Hyper-V 是微软开发的虚拟机,类似于 VMWare 或 VirtualBox,仅适用于 Windows 10.这是 Docker Des ...