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的更多相关文章
随机推荐
- wrk性能测试(详解)
一.简介 wrk 是一款针对 Http 协议的基准测试工具,它能够在单机多核 CPU 的条件下,使用系统自带的高性能 I/O 机制,如 epoll,kqueue 等,通过多线程和事件模式,对目标机器产 ...
- oracle中使用pl/sql进行的文件读写操作
第一次知道,可以使用pl/sql来进行文件的读写操作,嘿嘿,简单的试了下可行. 基本步骤如下: SQL> conn sys/sys@orcl as sysdba 已连接. SQL> cre ...
- PHP 对接第三方 LINE 登录,网上找到相关的不多 但是网上哪些乱七八糟的啰啰嗦嗦 要么就是怎么做的, 什么步骤 总会给你省略, 如果有幸你看到我的 可以放心的复制即用, 当然 你也可以用postman去尝试 不过我觉得既然做开发 就没必要那个了! 如果用postman再最后一步的时候 请用本文最下方式
* LINE 官方文档:https://developers.line.biz/en/docs/line-login/getting-started/* 开发者平台地址:https://develop ...
- 2013 ACM/ICPC Asia Regional Online —— Warmup2 ABEGKL
HDU4716 A. A Computer Graphics Problem A题目描述 题意:输出手机剩余电量,保证给出的数是10的倍数. 题解:水题,按题意输出即可. 代码: #include & ...
- git利用hooks实现自动部署
准备工作: 1.一台虚拟linux环境和window 开始工作 1.安装git(略) 2.创建git用户和创建test.git裸仓库 [root@localhost ~]# useradd -m gi ...
- MySQL查询基础
MySQL查询 DQL(Data Query Language ) 1.排序查询 # 语法: select 字段 from 表名 order by 字段1 [降序/升序],字段2 [降序/升序],.. ...
- Jenkins介绍与安装
什么是Jenkins Jenkins的优势和应用场景 Jenkins安装配置管理 安装Jenkins前的环境准备(Centos 7) 1.添加yum仓库源# wget -O /etc/yu ...
- Java.前端.Layer.open.btn验证无效
今天遇到了一个很可笑的问题,在.Layer弹窗open中设置了多个按钮,只有yes按钮有效,btn2点击后直接关闭弹窗,排查了2个小时后终于解决,就是btn2要return false! var in ...
- python 遍历文件夹下的所有文件
基础 import os # 遍历文件夹 def walkFile(file): for root, dirs, files in os.walk(file): # root 表示当前正在访问的文件夹 ...
- Flask DBUtils
作用:创建连接池,解决多线程问题 1.安装模块 pip3 install -i https://pypi.douban.com/simple DBUtils 2.settings.py(配置文件) f ...