Educational Codeforces Round 1D 【DFS求联通块】
1 second
256 megabytes
standard input
standard output
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of n × m cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.
At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one.
For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.
First line of the input contains three integers n, m and k (3 ≤ n, m ≤ 1000, 1 ≤ k ≤ min(n·m, 100 000)) — the museum dimensions and the number of starting positions to process.
Each of the next n lines contains m symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum.
Each of the last k lines contains two integers x and y (1 ≤ x ≤ n, 1 ≤ y ≤ m) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.
Print k integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
5 6 3
******
*..*.*
******
*....*
******
2 2
2 5
4 3
6
4
10
4 4 1
****
*..*
*.**
****
3 2
8
【题意】:给定一个n*m的地图,‘ . ' 是可通路,' * '是墙壁。有k次查询。每次查询,询问位置(x, y)(保证为字符.) 周围有多少个* 。
【分析】:由于题目会给出多个起始位置(至少10,000内),如果每个位置都进行一次dfs的话会超时。
Educational Codeforces Round 1D 【DFS求联通块】的更多相关文章
- 利用DFS求联通块个数
/*572 - Oil Deposits ---DFS求联通块个数:从每个@出发遍历它周围的@.每次访问一个格子就给它一个联通编号,在访问之前,先检查他是否 ---已有编号,从而避免了一个格子重复访问 ...
- 【紫书】Oil Deposits UVA - 572 dfs求联通块
题意:给你一个地图,求联通块的数量. 题解: for(所有还未标记的‘@’点) 边dfs边在vis数组标记id,直到不能继续dfs. 输出id及可: ac代码: #define _CRT_SECURE ...
- 用dfs求联通块(UVa572)
一.题目 输入一个m行n列的字符矩阵,统计字符“@”组成多少个八连块.如果两个字符所在的格子相邻(横.竖.或者对角线方向),就说它们属于同一个八连块. 二.解题思路 和前面的二叉树遍历类似,图也有DF ...
- HDU - 1213 dfs求联通块or并查集
思路:给定一个无向图,判断有几个联通块. AC代码 #include <cstdio> #include <cmath> #include <algorithm> ...
- 中矿新生赛 H 璐神看岛屿【BFS/DFS求联通块/连通块区域在边界则此连通块无效】
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld 题目描述 璐神现在有张n*m大小的地图,地图上标明了陆地(用 ...
- K - Ancient Messages(dfs求联通块)
K - Ancient Messages Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- POJ 1562 Oil Deposits (并查集 OR DFS求联通块)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14628 Accepted: 7972 Des ...
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
随机推荐
- shell脚本获取网页快照并生成缩略图
获取网页快照并生成缩略图可分两步进行: 1.获取网页快照 2.生成缩略图 获取网页快照 这里我们用 phantomjs 来实现.关于 phantomjs 的详细用法可参考官方网站. 1.安装 我的环境 ...
- 详解zabbix2.2.2安装部署(Server端篇)
今天开始安装zabbix.zabbix需要LNMP或者LAMP环境.环境的搭建不在本章范围内. LNMP环境配置 Linux安装:http://www.osyunwei.com/archives/10 ...
- jsonp、瀑布流布局、组合搜索、多级评论(评论树)、Tornado初识
1.JSONP原理剖析以及实现 1.1 同源策略限制 用django分别建立两个项目,jsonp01和jsonp02,然后再在这两个项目里分别建立一个app,比如名字叫jsonp1.jsonp2:js ...
- Python编码、流程控制、格式化输出
Python编码 初始编码: 电脑的传输,还有储存,实际上都是010101010 ASCII码: (American Standard Code for Information Interchange ...
- [译]15-spring 自动装配
前面的章节我们已经学习了如何使用bean元素在xml配置文件中声明一个bean.也学习了如何使用bean的子元素contructor-arg 和property进行bean的依赖项的注入. 之前bea ...
- unity值得推荐的网址
免费字体下载网站:http://www.dafont.com/ 免费声音文件下载网站:http://freesound.org/ http://incompetech.com/mus ...
- Python全栈工程师(字符串/序列)
ParisGabriel Python 入门基础 字符串:str用来记录文本信息字符串的表示方式:在非注释中凡是用引号括起来的部分都是字符串‘’ 单引号“” 双引号''' ''' ...
- 孤荷凌寒自学python第六十三天学习mongoDB的基本操作并进行简单封装2
孤荷凌寒自学python第六十三天学习mongoDB的基本操作并进行简单封装2 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第九天. 今天继续学习mongoDB的简单操作, ...
- hadoop 客户的的使用
${HADOOP_HOME}/bin/hadoop job Usage: JobClient <command> <args> [-submit <job-file> ...
- UVALive 4764 简单dp水题(也可以暴力求解)
B - Bing it Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status ...