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的更多相关文章
随机推荐
- Linux学习笔记(一):什么是挂载?mount的用处在哪?
关于挂载的作用一直不是很清楚,今天在阅读教材时看见了mount这个命令,发现它的用处很隐晦但非常强大.奈何教材说的不明朗,因此在网上整合了一些优秀的解释,看完之后豁然开朗. 1.提一句Windows下 ...
- HTTP请求中的GET-POST方式
目录 一.前言部分(概念) 二.对比 GET 与 POST 二者最大的差异 GET 与 POST 请求本质上并无区别 深层了解:POST 请求产生两个数据包? 三.两种请求方式如何灵活使用? 四.常见 ...
- spring-boot第一章:快速开始
快速开始 创建pom.xml文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...
- react路由的跳转和传参
1.路由的跳转 一.DOM跳转 在需要跳转的页面导入import {Link} from 'react-router-dom',在需要跳转的地方使用link标签的to属性进行跳转,路由配置文件中导出的 ...
- Sql Server学习笔记
1.指定路径创建数据库 create database student on--创建库的时候必须写 ( name=student, filename='E:\database\student.mdf' ...
- dp-LCS(递归输出最短合串)
Problem Description The company "21st Century Fruits" has specialized in creating new sort ...
- Java知识体系框架
前言:自从出生,每个人都是一个学习者或探索者.永远保持一颗谦逊的心态,遵循一定的方法和规范,去学习和实践,永远记得走走停停,多回头看看自己走过的路,温故而知新,也能更好地指导未来的路怎么走(同样,本篇 ...
- python+opencv中最近出现的一些变化( OpenCV 官方的 Python tutorial目前好像还没有改过来?) 记一次全景图像的拼接
最近在学习过程中发现opencv有了很多变动, OpenCV 官方的 Python tutorial目前好像还没有改过来,导致大家在学习上面都出现了一些问题,现在做一个小小的罗列,希望对大家有用 做的 ...
- Matplotlib从兴趣到实践
先看下Matplotlib实现的效果 是不是出现了也想敲一个的心动,那让我们一起来了解Matplotlib吧 Matplotlib安装 1.Windows系统安装Matplotlib 进入到cmd的命 ...
- SSAS Tabular表格模型实现动态权限管理
最近忽然对SSAS产生了浓厚兴趣,我看博客园上也米有写关于SSAS 2016下表格模型实现动态权限管理的文章,最近鼓捣了一下微软的样例,鼓捣好了,把过程中遇到的一些问题写出来,抛砖引玉,也算给自己一个 ...