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.

Input

The first line of the input contains three integers nm 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.

Output

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.

Examples
input
5 4 1
****
*..*
****
**.*
..**
output
1
****
*..*
****
****
..**
input
3 3 0
***
*.*
***
output
1
***
***
***
Note

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.

/*
不碰边界的连通块算是一个湖,给你要保留的湖的数目,一次填一个点,求填湖的最少次数
sb爆搜,注意最后那个贪心选湖,还有那个边界的判断,比赛写错了
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct orz{
int p;
int sz;
};
orz lke[];
int mp[][],vis[][],cnt,n,m,k,tot;
bool ok[],sgn[];
int dx[] = {-,,,};
int dy[] = {,,,-};
char cmd;
bool jud(int y,int x){
return y >= && x >= && y <= n && x <= m && !vis[y][x] && mp[y][x] == ;
}
bool dfs(int y,int x){
vis[y][x] = cnt;
lke[cnt].sz++;
int ny,nx;
int gg = false;
for(int i = ;i < ;i++){
ny = y + dy[i];
nx = x + dx[i];
if(ny < || ny > n || nx < || nx > m) gg = true;
if(jud(ny,nx)) if(!dfs(ny,nx)) gg = true;
}
if(gg) return false;
else return true;
}
bool cmp(orz a,orz b){
return a.sz < b.sz;
}
int main(){
cin>>n>>m>>k;
for(int i = ;i <= n;i++){
for(int j = ;j <= m;j++){
scanf("%c",&cmd);
while(cmd != '*' && cmd != '.') scanf("%c",&cmd);
if(cmd == '*') mp[i][j] = ;
else if(cmd == '.') mp[i][j] = ;
}
}
for(int i = ;i <= n;i++){
for(int j = ;j <= m;j++){
if(mp[i][j] == && !vis[i][j]){
cnt++;
lke[cnt].p = cnt;
ok[cnt] = dfs(i,j);
if(ok[cnt]) tot++;
}
}
}
sort(lke+,lke++cnt,cmp);
int chs = ,ans = ;
for(int i = ;i <= cnt;i++){
if(chs >= tot - k) break;
if(ok[lke[i].p]){
sgn[lke[i].p] = true;
chs++;
ans += lke[i].sz;
} }
cout<<ans<<endl;
for(int i = ;i <= n;i++){
for(int j = ;j <= m;j++){
if(mp[i][j] == || sgn[vis[i][j]]) cout<<"*";
else cout<<".";
}
cout<<endl;
}
return ;
}

cf723d Lakes in Berland的更多相关文章

  1. CF723D. Lakes in Berland[DFS floodfill]

    D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. CF723D 【Lakes in Berland】

    题目链接 题解 CF723D [Lakes in Berland] 首先将边界的水用bfs处理掉 再将中间的每一个湖泊处理出来,存入一个结构体内,结构体里记录湖泊大小和开始点 将湖泊排序从小往大填满, ...

  3. codeforces 723D: Lakes in Berland

    Description The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × ...

  4. Codeforces Round #375 (Div. 2)——D. Lakes in Berland(DFS连通块)

    D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #375 (Div. 2) D. Lakes in Berland dfs

    D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. codeforces723 D. Lakes in Berland(并查集)

    题目链接:codeforces723 D. Lakes in Berland 参考博客:http://www.cnblogs.com/Geek-xiyang/p/5930245.html #inclu ...

  7. Codeforces Round #375 (Div. 2) D. Lakes in Berland 贪心

    D. Lakes in Berland 题目连接: http://codeforces.com/contest/723/problem/D Description The map of Berland ...

  8. Codeforces Round #375 (Div. 2) D. Lakes in Berland (DFS或并查集)

    D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. 【29.70%】【codeforces 723D】Lakes in Berland

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. strstr 函数的实现

    strstr函数:返回主串中子字符串的位置后的所有字符. #include <stdio.h> const char *my_strstr(const char *str, const c ...

  2. 架构实例之Demo_JSP_JavaBean_Servlet

    架构实例之Demo_JSP_JavaBean_Servlet 1.开发工具和开发环境       开发工具: MyEclipse10,JDK1.6.0_13(32位),Tomcat7.0(32位),m ...

  3. 在Azure上实现Linux Server故障转移

    要充分利用公有云的弹性扩展和高可用, 首先要在应用系统层面支持横向扩展(scale out),这个说起来很容易,或者说对新开发的应用系统而言已经成为标配.但是对已有的.老旧的应用系统来说,这就比较困难 ...

  4. Java公众号推荐 - BeJavaGod

    今天新创建了一个java的公众号,会经常更新java的文章,有兴趣的朋友关注一下吧- 主要内容基本是跟本微博同步的 不管是做java的新手还是高手,内行还是外行,java还是非java,一起关注,一起 ...

  5. Python的列表推导式,字典推导式,集合推导式使用方法

    推导式分为列表推导式(list),字典推导式(dict),集合推导式(set)三种 1.列表推导式也叫列表解析式.功能:是提供一种方便的列表创建方法,所以,列表解析式返回的是一个列表格式:用中括号括起 ...

  6. 数据库_MYSQL

     数据库简介 数据库分类:关系型数据库.非关系型数据库 常用的关系型数据库有:orcale .mysql .sql server等等 常用的非关系型数据库有: Memcached.redis.mong ...

  7. 关于Oracle AUTONOMOUS TRANSACTION(自治事务)的介绍

    AUTONOMOUS TRANSACTION(自治事务)的介绍 在基于低版本的ORACLE做一些项目的过程中,有时会遇到一些头疼的问题,比如想在执行当前一个由多个DML组成的transaction(事 ...

  8. 解决某些Android Permission denied

    最近遇到一个问题,总是在模拟器重报Permission denied错误,于是我直接在手机上测试,发现没有错误,于是很郁闷,反复在AndroidManifest中加入权限   <uses-per ...

  9. silverlight 4.0 的oob模式下,调用com通过wmi重启自身进程 killself

    silverlight目前开发的应用,想做到系统内注销后自动重新启动下 sllauncher.exe ,实现方式是通过WMI的COM接口,获取到当前应用的执行命令行(CommandLine):并通过s ...

  10. 使用PhpDocumentor生成文档

    一,网站根目录执行 $ composer require --dev phpdocumentor/phpdocumentor 二,进入vendor/bin/目录执行 $phpdoc -d D:\ser ...