Educational Codeforces Round 5 C. The Labyrinth
2016-01-15 22:01
381 查看
C. The Labyrinth
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells
are marked with '.', impassable cells are marked with '*'.
Let's call two empty cells adjacent if they share a side.
Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component.
For each impassable cell (x, y) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the
number of cells) of the connected component which contains (x, y). You should do it for each impassable cell independently.
The answer should be printed as a matrix with n rows and m columns.
The j-th symbol of the i-th
row should be "." if the cell is empty at the start. Otherwise the j-th
symbol of the i-th row should contain the only digit —- the answer modulo 10.
The matrix should be printed without any spaces.
To make your output faster it is recommended to build the output as an array of n strings having length m and
print it as a sequence of lines. It will be much faster than writing character-by-character.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printfinstead of cin/cout in
C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 1000)
— the number of rows and columns in the field.
Each of the next n lines contains m symbols:
"." for empty cells, "*" for impassable cells.
Output
Print the answer as a matrix as described above. See the examples to precise the format of the output.
Sample test(s)
input
output
input
output
Note
In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner
cell will be empty then it will be included to component of size 3 (corner).
解题报告:Editorial of Educational Codeforces Round 5
对于每一个障碍,让你输出去掉这个障碍之后,这个点所在的连通块的大小是多少
答案需要%10
上下左右的连通块加在一起就好了
但是有一个问题,就是你有可能加重复,所以我们需要
处理原来连通块,我是用的dfs做的
解题报告:Editorial of Educational Codeforces Round 5
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells
are marked with '.', impassable cells are marked with '*'.
Let's call two empty cells adjacent if they share a side.
Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component.
For each impassable cell (x, y) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the
number of cells) of the connected component which contains (x, y). You should do it for each impassable cell independently.
The answer should be printed as a matrix with n rows and m columns.
The j-th symbol of the i-th
row should be "." if the cell is empty at the start. Otherwise the j-th
symbol of the i-th row should contain the only digit —- the answer modulo 10.
The matrix should be printed without any spaces.
To make your output faster it is recommended to build the output as an array of n strings having length m and
print it as a sequence of lines. It will be much faster than writing character-by-character.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printfinstead of cin/cout in
C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 1000)
— the number of rows and columns in the field.
Each of the next n lines contains m symbols:
"." for empty cells, "*" for impassable cells.
Output
Print the answer as a matrix as described above. See the examples to precise the format of the output.
Sample test(s)
input
3 3 *.* .*. *.*
output
3.3 .5. 3.3
input
4 5 **..* ..*** .*.*. *.*.*
output
46..3 ..732 .6.4. 5.4.3
Note
In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner
cell will be empty then it will be included to component of size 3 (corner).
解题报告:Editorial of Educational Codeforces Round 5
题意
给你n行m列的矩阵,矩阵*表示障碍,.表示空地对于每一个障碍,让你输出去掉这个障碍之后,这个点所在的连通块的大小是多少
答案需要%10
题解:
这个块的联通块大小,实际上是由四个部分所组成的上下左右的连通块加在一起就好了
但是有一个问题,就是你有可能加重复,所以我们需要
处理原来连通块,我是用的dfs做的
解题报告:Editorial of Educational Codeforces Round 5
相关文章推荐
- Educational Codeforces Round 5 D. Longest k-Good Segment
- 在知乎上给评论加入跳转链接--XSS练手
- MacBook外接显示器设置方法(新手入门贴)
- java加密、解密技术系列:Base64
- 网易新闻
- 针对之前的Canvas的一个小小的改版,算作canvas(二)吧
- 蓝懿IOS阶段测试
- 插入排序的一种尾递归实现-C
- UI_1
- python学习第十课续 :线程池
- linux变量篇(三) 命令行参数变量传递
- 怎样学习java?
- 开发中常见问题
- Ugly Number
- C#基础练习(时间的三连击)
- 欢迎使用CSDN-markdown编辑器
- C#基础练习(时间的三连击)
- 《笨办法学Python》 第13课手记
- 利用sort函数对数组进行排序【java】
- ZigBee中PANID的修改