Codeforces_723_D
http://codeforces.com/problemset/problem/723/D
dfs找出每个湖,保存坐标和大小,按大小排序,填充湖即可,注意湖的数量最多会有1250个。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std; int n,m,k,dir[][] = {-,,,-,,,,},ok,cnt = ,sizee,vis[][] = {};
char mp[][]; struct lake
{
int x,y,cnt;
}l[]; bool cmp(struct lake a,struct lake b)
{
return a.cnt < b.cnt;
} void dfs1(int x,int y)
{
vis[x][y] = ;
sizee++;
for(int i = ;i < ;i++)
{
int xx = x+dir[i][],yy = y+dir[i][];
if(xx < || yy < || xx >= n || yy >= m)
{
ok = ;
continue;
}
if(mp[xx][yy] == '*' || vis[xx][yy]) continue; dfs1(xx,yy);
}
} void dfs2(int x,int y)
{
mp[x][y] = '*';
for(int i = ;i < ;i++)
{
int xx = x+dir[i][],yy = y+dir[i][];
if(xx < || yy < || xx >= n || yy >= m) continue;
if(!vis[xx][yy]) continue;
vis[xx][yy] = ;
dfs2(xx,yy);
}
} int main()
{
scanf("%d%d%d",&n,&m,&k);
getchar();
int x = ;
while(gets(mp[x++]));
for(int i = ;i < n;i++)
{
for(int j = ;j < m;j++)
{
sizee = ;
ok = ;
if(mp[i][j] == '.' && !vis[i][j])
{
dfs1(i,j);
if(ok)
{
l[cnt].x = i;
l[cnt].y = j;
l[cnt++].cnt = sizee;
}
}
}
}
sort(l,l+cnt,cmp);
int endd = cnt-k,ans = ;
for(int i = ;i < endd;i++)
{
ans += l[i].cnt;
dfs2(l[i].x,l[i].y);
}
printf("%d\n",ans);
for(int i = ;i < n;i++) puts(mp[i]);
return ;
}
Codeforces_723_D的更多相关文章
随机推荐
- 使用Rancher Server部署本地多节点K8S集群
当我第一次开始我的Kubernetes之旅时,我一直在寻找一种设置本地部署环境的方式.很多人常常会使用minikube或microk8s,这两者非常适合新手在单节点集群环境下进行操作.但当我已经了解了 ...
- mongodb 更新嵌套数组的值
概要 本文主要讲述在 mongodb 中,怎么更新嵌套数组的值. 使用$更新数组 基本语法 { "<array>.$" : value } 可以用于:update, ...
- schedule of 2016-10-09~2016-10-16(Sunday~Sunday)——1st semester of 2nd Grade
most important things to do 1.prepare for toefl 2.joint phd preparations 3.ieee trans thesis to writ ...
- 迷你PS小程序-集成的开放式画报、油墨电子签名、图片拖拽可单独食用
米娜桑,哦哈哟~ 个人制作,该文章主要讲解最近基于uni-app框架编写的集图文拖拽等多方位编辑.油墨电子签名.开放式海报于一体的小程序的制作思路和实现代码. 目录 1.完整源码链接 2.实现思路 3 ...
- nginx 负载均衡及反向代理
Nginx简介 Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师开发,官方测试nginx能够支支撑5万并发链接,并且cpu.内存 ...
- 原生javascript 基础动画函数封装(二)
<!DOCTYPE html> <html> <head> <title></title> <style type="tex ...
- Tensorflow内存暴涨问题
1.目前只总结出两条 创建saver实例saver = tf.train.Saver()放在循环外面 不循环初始化变量 sess.run(tf.global_variables_initializer ...
- .NET Core学习笔记(3)——async/await中的Exception处理
在写了很多年.NET程序之后,年长的猿类在面对异步编程时,仍不时会犯下致命错误,乃至被拖出去杀了祭天.本篇就async/await中的Exception处理进行讨论,为种族的繁衍生息做出贡献……处理a ...
- Logback源码分析
在日常开发中经常通过打印日志记录程序执行的步骤或者排查问题,如下代码类似很多,但是,它是如何执行的呢? package chapters; import org.slf4j.Logger; impor ...
- 网站 cache control 最佳实践
推荐阅读: 2020年软件开发趋势 高并发案例 - 库存超发问题 负载均衡的分类及算法 异地多活架构 Postman 的替代品来了 有时,当第二次访问网站时,看起来比较怪,样式不正常. 通常,是因为 ...