A10629 | Lakes in Berland
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The map of Berland is a rectangle of the size $n×m$ , which consists of cells of size $1×1$ . Each cell is either land or water. The map is surrounded by the ocean.
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly $k$ lakes in Berland. Note that the initial number of lakes on the map is not less than $k$ .
Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it's possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it's impossible to add one more water cell to the set such that it will be connected with any other cell.
You task is to fill up with the earth the minimum number of water cells so that there will be exactly $k$ lakes in Berland. Note that the initial number of lakes on the map is not less than $k$ .
输入格式
The first line of the input contains three integers $n$ , $m$ and $k$ ( $1<=n,m<=50$ , $0<=k<=50$ ) — the sizes of the map and the number of lakes which should be left on the map.
The next $n$ lines contain $m$ characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '\*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least $k$ lakes.
The next $n$ lines contain $m$ characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell is water) or '\*' (it means that the corresponding cell is land).
It is guaranteed that the map contain at least $k$ lakes.
输出格式
In the first line print the minimum number of cells which should be transformed from water to land.
In the next $n$ lines print $m$ symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
In the next $n$ lines print $m$ symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.
It is guaranteed that the answer exists on the given data.
输入输出样例
输入 #1
5 4 1 **** *..* **** **.* ..**
输出 #1
1 **** *..* **** **** ..**
输入 #2
3 3 0 *** *.* ***
输出 #2
1 *** *** ***
In the first example there are only two lakes — the first consists of the cells $(2,2)$ and $(2,3)$ , the second consists of the cell $(4,3)$ . It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with the ocean.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted