【紫书】Oil Deposits UVA - 572 dfs求联通块
题意:给你一个地图,求联通块的数量。
题解:
for(所有还未标记的‘@’点)
边dfs边在vis数组标记id,直到不能继续dfs。
输出id及可;
ac代码:
#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include<stdio.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<iostream>
#include<string.h>
#include<queue>
#include<string>
#include<sstream>
using namespace std;
const int maxn = +;
string map[maxn];
int ans;
int idx[maxn][maxn];
int n, m;
void dfs(int r,int c,int id) {
if (r<||c<||r>=n||c>=m||map[r][c] == '*'||idx[r][c])return;
idx[r][c] = id;
for(int dr=-;dr<=;dr++)
for (int dc = -; dc <= ; dc++)
if(dr||dc)dfs(r + dr, c + dc,id);
}
int main(){ while (cin >> n >> m) {
if (n == && m == )break;
ans = ;
memset(idx, , sizeof(idx));
for (int i = ; i < n; i++) {
cin >> map[i];
}
for (int i = ; i < n; i++)
for (int j = ; j < m; j++)
if (idx[i][j] == && map[i][j] == '@') dfs(i, j, ++ans);
cout << ans<<endl;
}
return ;
}
【紫书】Oil Deposits UVA - 572 dfs求联通块的更多相关文章
- UVA 572 Oil Deposits油田(DFS求连通块)
UVA 572 DFS(floodfill) 用DFS求连通块 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format: ...
- UVA 572 dfs求连通块
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...
- 利用DFS求联通块个数
/*572 - Oil Deposits ---DFS求联通块个数:从每个@出发遍历它周围的@.每次访问一个格子就给它一个联通编号,在访问之前,先检查他是否 ---已有编号,从而避免了一个格子重复访问 ...
- 用dfs求联通块(UVa572)
一.题目 输入一个m行n列的字符矩阵,统计字符“@”组成多少个八连块.如果两个字符所在的格子相邻(横.竖.或者对角线方向),就说它们属于同一个八连块. 二.解题思路 和前面的二叉树遍历类似,图也有DF ...
- Oil Deposits UVA - 572
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...
- POJ 1562 Oil Deposits (并查集 OR DFS求联通块)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14628 Accepted: 7972 Des ...
- ACM:油田(Oil Deposits,UVa 572)
/* Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- HDU - 1213 dfs求联通块or并查集
思路:给定一个无向图,判断有几个联通块. AC代码 #include <cstdio> #include <cmath> #include <algorithm> ...
- 油田 (Oil Deposits UVA - 572)
题目描述: 原题:https://vjudge.net/problem/UVA-572 题目思路: 1.图的DFS遍历 2.二重循环找到相邻的八个格子 AC代码: #include <iostr ...
随机推荐
- 8 -- 深入使用Spring -- 8... Spring整合Hibernate
8.8 Spring整合Hibernate 8.8.1 Spring提供的DAO支持 8.8.2 管理Hibernate的SessionFactory 8.8.3 实现DAO组件的基类 8.8.4 传 ...
- Splash resource_timeout 属性
resource_timeout属性用于设置加载的超时时间,单位是秒,如果设置为 0 代表不检测超时,如下,设置超时时间为 0.1 秒: function main(splash) splash.re ...
- RabbitMq 之简单队列
简单队列类似于我们的生产者,消费者, 一个生产者,对应一个消费者. 直接上代码: package com.j1.rabbitmq.simple; import com.j1.rabbitmq.util ...
- C语言从零开始(十四)-字符串处理
在软件开发过程中,字符串的操作相当频繁.在标准C语言库中提供了很多字符串处理的函数.今天我们来介绍一些常用的字符串处理函数.1. 字符串输入输出1.1 printf() scanf() 之前我们学习过 ...
- 目前学习.net时间让我摸不着头脑的事情
呜呜,不太喜欢做笔记,只喜欢把自己不懂的和预习时间有麻烦的简单记下,所以这里也是能可以让我写下我们的学习点滴··· 今天学习了<1>.变量的作用域,在想是不是之前听过的局部变量和全局变量? ...
- oracle URL参数获取
改函数主要是从URL中获取参数例如 sssss.html?cur=aaa&ref=cccc 调用方式:f_querystr(url,'cur','&'); CREATE OR REPL ...
- IOS 第三方支付的使用:支付宝
本文转载至 http://blog.csdn.net/u014011807/article/details/47726799 总结一下支付宝iOS使用步骤: 1 第三方支付:支付宝 使用过程: 1. ...
- <转>Python: __init__.py 用法
转自 http://www.cnblogs.com/BeginMan/p/3183629.html python的每个模块的包中,都有一个__init__.py文件,有了这个文件,我们才能导入这个目录 ...
- 基于VLAN的二三层转发
[章节内容]1 MAC地址2 冲突域和广播域3 集线器.交换机.路由器 3.1 集线器 3.2 网桥和交换机 3.3 路由器4 VLAN 4.1 VLAN帧格式 4.1.1 ...
- 【truffle】Error: `truffle init` no longer accepts a project template name as an argument.
下载范例工程时候.使用命令报错 truffle init webpack 错误如下: Error: `truffle init` no longer accepts a project templat ...