Codeforces-723D- Lakes in Berland(DFS)

本文介绍了一种解决Berland地图上湖泊填土问题的算法,目标是最小化填土操作次数以达到指定的湖泊数量。通过深度优先搜索确定湖泊范围,并采用结构体存储湖泊信息,最终按湖泊面积排序来决定哪些湖泊需要被填平。
点击打开链接

D. Lakes in Berland

time limit per test
2 seconds
memory limit per test
256 megabytes

input

standard input

output

standard output


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 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.

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
***
***
***

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,t,ans,ok;
int l[4]={0,0,-1,1},r[4]={-1,1,0,0};
int viso[101][101];
char map[101][101];
struct node
{
	int x,y,z;//存储 湖波的位置数量 
}d[10001];
void dfs(int x,int y)
{
	if(x==0||y==0||x==n-1||y==m-1){//判定是否在边界 
		ok=0;
	}
	viso[x][y]=1;
	ans++;//点的数量 
	for(int i=0;i<4;i++){
		int xx=x+l[i],yy=y+r[i];
		if(xx>=0&&yy>=0&&xx<n&&yy<m&&!viso[xx][yy]&&map[xx][yy]=='.'){//深搜出"." 
			dfs(xx,yy);
		}
	}
}
void DFS(int x,int y)//把所有不满足条件的"."变成"*"; 
{
	map[x][y]='*';
	for(int i=0;i<4;i++){
		int xx=x+l[i],yy=y+r[i];
		if(map[xx][yy]=='.'){
			DFS(xx,yy);
		}
	}
}
bool cmp(node i,node j)//比较出所有湖的面积大小 
{
	return i.z>j.z;
}
int main()
{
	scanf("%d %d %d",&n,&m,&t);
	for(int i=0;i<n;i++){
		scanf("%s",&map[i]);
	}
	int l=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(!viso[i][j]&&map[i][j]=='.'){//判定点并储存在结构体中 
				ok=1;
				ans=0;
				dfs(i,j);
				if(ok){
					d[l].x=i;
					d[l].y=j;
					d[l++].z=ans;
				}
			}
		}
	}
	sort(d,d+l,cmp);//排序 
	int sum=0;
	for(int i=t;i<l;i++){
		sum+=d[i].z;
		DFS(d[i].x,d[i].y);
	}
	printf("%d\n",sum);
	for(int i=0;i<n;i++){
		printf("%s\n",map[i]);
	}
return 0;
}


内容概要:本文详细记录了对一个Android ARM64静态ELF文件中字符串加密机制的逆向分析过程。该ELF文件的所有字符串均被加密,无法通过常规strings命令或IDA直接识别。作者通过分析发现,加密字符串存储在.rodata段,其解密所需信息(包括密文地址、长度和16位密钥)保存在.data.rel.ro段的40字节描述符中。核心解密函数sub_10F408采用自反的双pass流密码算法,结合固定密钥KEY_TERM(由.data段24字节数据计算得出),实现字节级非线性、位置与长度相关的加密。文章还复现了完整的Python解密脚本,并揭示了该保护机制的本质为代码混淆而非强加密,最终成功批量解密全部956条字符串,暴露程序真实行为,如shell命令模板、设备标识篡改、网络重置等操作。此外,文中还提及未启用的自定义壳框架及其反dump设计。; 适合人群:具备逆向工程基础的安全研究人员、二进制分析人员及对ELF保护技术感兴趣的开发者。; 使用场景及目标:①学习ELF二进制中字符串加密的典型实现方式与逆向突破口;②掌握从结构识别、函数追踪到算法还原的完整逆向流程;③理解“绑定二进制”的完整性校验设计及其局限性;④实践编写IDAPython脚本自动化提取与解密敏感数据。; 阅读建议:此资源以实战案例驱动,不仅展示技术细节,更强调逆向思维与验证方法,建议读者结合IDA调试环境,逐步跟随文中步骤进行动态分析与算法验证,深入理解每一步的推理依据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值