A. Maze Codeforces Round 222 (Div. 1)

关于“为爱发电”的一些说明~~ 专栏教学资料+工程文件 阅读详情

Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.

Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly k empty cells into walls so that all the remaining cells still formed a connected area. Help him.

Input

The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze.

Each of the next n lines contains m characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.

Output

Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").

It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.

Examples

input

Copy

3 4 2
#..#
..#.
#...

output

Copy

#.X#
X.#.
#...

input

Copy

5 4 5
#...
#.#.
.#..
...#
.#.#

output

Copy

#XXX
#X#.
X#..
...#
.#.#

题目大致意思:给你一个n行m列的图,"#"为墙,"."为陆地,初始联通陆地只有一块,让你填入k个"X" 墙后,联通陆地还是一块。

主要考点为深搜。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

const ll N = 1e3+7;
ll n,m,k;
string s[N];
bool vis[N][N];
ll dir[4][2]={0,1,1,0,0,-1,-1,0};

void dfs(ll x ,ll y){
	vis[x][y]=1;
	for(ll i = 0 ; i < 4 ; i ++){
		ll tx = x + dir[i][0];
		ll ty = y + dir[i][1];
		if(tx < 0 || ty < 0 || tx >= n || ty >= m || s[tx][ty] != '.' || vis[tx][ty])continue;
		dfs(tx,ty);
	}
	if(k > 0){
		k--;
		s[x][y]='X';
	}
	return;
}

void solve(){
	cin >> n >> m >> k;
	for(ll i = 0 ; i < n ; i ++)cin >> s[i];
	ll x=0,y=0;
	bool f=0;
	for(; x < n ; x ++){
		if(f)break;
		for(y = 0 ; y < m ; y ++){
			if(s[x][y]=='.')f=1;
			if(f)break;
		}
	}
	dfs(x,y);
	for(ll i = 0 ; i < n ; i ++)cout << s[i] << endl;
	return;
}

int main(){
	ll t=1;//cin >> t;
	while(t--)solve();
	return 0;
}

Codex入门19-数据库操作(解放双手:用自然语言写SQL、建表和数据迁移) 写 SQL 是后端开发的日常,但复杂的 JOIN、子查询、窗口函数总让人头疼。本文教你用 Codex CLI 实现:自然语言直接生成 CREATE TABLE、复杂 SQL 查询、数据库迁移脚本(Prisma/Knex/Alembic)、ORM 模型代码(SQLAlchemy/TypeORM)、甚至自动生成数据库文档。重点强调安全红线——永远不要让 AI 直接连接生产数据库。从需求描述到完整数据库层代码,一篇搞定。 阅读详情

相关推荐

高通平台Camera sensor bring up!

Qualcomm Camera sensor bring up!0. 准确1. Kernel 底层驱动配置1.1 dtsi1.2 pinctrl2. Chi-Cdk XML 配置2.1 sensormodule2.2 sensor3. CHECK 本文主要针对高通平台SM7250进行描述,当然高通平台可能基本都差不多【第一个项目】 —only for sensor probe sucess. 0....

Understand-image 9239

Codeforces Round #222 (Div. 1) A. Maze

题意:有n*m矩阵,'.'为空地,'#'为墙。在空地上添加k堵墙使得最后空地联通。保证有解。 思路:随便送任何一个空地走,走到不能走为止,那么这个位置就可以设为'X'。然后回溯将路径上的空地都设为'x'。很明显最后的图是联通的。 #include using namespace std; int n,m,k; char ch[501][501]; int vis[501][501];

caoyi0905 769

【ROS2】MOMO的鱼香ROS2(三)ROS2入门篇——ROS2第一个节点

【ROS2】MOMO的鱼香ROS2(三)ROS2入门篇——ROS2第一个节点

qq_44703886的博客 3613

Codeforces Round #222 (Div. 1) A. Maze dfs

A. Maze 题目连接: http://codeforces.com/contest/377/problem/A Description Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one ...

weixin_34128237的博客 132

(超详细)Scala环境搭建(scala-2.12.15、IDEA2021.1.3)

Scala环境搭建(scala-2.12.15、IDEA2021.1.3) JunLeon——go big or go home 目录 Scala环境搭建(scala-2.12.15、IDEA2021.1.3) 一、Scala概述 1、什么是Scala? 2、Scala发展史 3、Scala与Java的关系 二、Scala环境搭建 1、环境准备 2、Scala安装与配置环境变量 3、验证Scala 三、编写第一个Scala程序 1、使用IDEA创建maven工程 2、.

JunLeon的博客 3万+

【QT+PCL】串口读取单线激光雷达数据并在QVtkWidget组件中实时刷新(一)

(本文主要记录开发过程以及遇到的困难及解决方式)

2301_76329543的博客 3067

Codeforces Round #222 (Div. 1)A. Maze(深搜)

传送门 Description Pavel loves grid mazes. A grid maze is ann × mrectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and h...

weixin_30418341的博客 145

手把手教你用TiggerRamDisk绕过iPhone/iPad激活锁(支持iOS16.3,Win/Mac双平台保姆级教程)

本文详细介绍了如何使用TiggerRamDisk工具绕过iPhone/iPad的激活锁,支持iOS16.3系统,并提供Windows和Mac双平台的保姆级教程。从工具准备、设备连接到核心解锁流程,一步步指导用户完成操作,帮助二手设备或旧设备重获新生。

weixin_29323493的博客 907

Codeforces Round #222 (Div. 1) 377A - Maze (连通块)

【题解】Codeforces Round #222 (Div. 1) 377A - Maze (连通块)

qq_52801833的博客 145

别再搞混了!Vue3里xgplayer播放FLV视频与FLV直播流,配置到底差在哪?

本文详细解析了在Vue3项目中使用xgplayer播放FLV视频与FLV直播流的配置差异,帮助开发者避免常见错误。通过对比点播与直播的核心协议差异、插件选择及配置参数,提供实战代码示例和性能优化技巧,确保流畅播放体验。特别针对直播流场景,深入讲解专属配置和问题排查方法。

weixin_28687331的博客 150

Python全栈入门到实战【基础篇 22】生成器与迭代器:底层逻辑与实战场景

Python迭代器与生成器:惰性求值的高效实践 摘要:本文深入解析Python中迭代器和生成器的核心机制与应用场景。迭代器通过实现__iter__()和__next__()方法实现惰性求值,适合处理大数据集和无限序列。生成器作为迭代器的简化实现,通过yield关键字自动实现迭代器协议,代码更简洁。文章详细对比了可迭代对象与迭代器的区别,演示了自定义迭代器和生成器函数的实现方式,并介绍了生成器表达式这一高效替代列表推导式的方案。通过斐波那契数列等实例,展示了惰性求值在内存优化方面的优势,以及生成器在流式数据处

那些看似不起波澜的日复一日,会在某天让你看到坚持的意义 3260

Codeforces Round #222 (Div. 1) (ABCDE)

377A Maze 大意: 给定棋盘, 保证初始所有白格连通, 求将$k$个白格变为黑格, 使得白格仍然连通. $dfs$回溯时删除即可. #include <iostream> #include <functional> #include <sstream> #include <algorithm> #includ...

weixin_30617695的博客 217

芒果YOLO11改进106:检测头篇DynamicHead动态检测头:基于DynamicHead,二次原创提出SATNeXt模块,提出全新的动态DynamicSatDetect

检测头篇DynamicHead动态检测头:基于DynamicHead,二次原创提出SATNeXt模块,提出全新的动态DynamicSatDetect

包括YOLOv5、YOLOv7、YOLOv8等模型改进 772

Codeforces Round #222 (Div. 1) Maze —— dfs(连通块)

题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然为连通的。把问题反过来,其实就是求tot-k的连通图。dfs:在搜索过的空格中做个标记,同时更新连通个数。 代码如下: 1 #include<cstd...

alince20008的博客 82

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

【索引】CodeForces Round #222 (Div. 2)

Problem A: Playing with Dice (378A) 题目大意:两个人猜数1~6,给出a和b,然后随机丢一个色子,问说接近a的可能,相等的可能,以及接近b的可能。 解题思路:完完全全的签到题。 #include #include #include int main() { int a, b; int x = 0, y = 0, z = 0

不慌不忙、不急不躁 1256

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

刷题之Codeforces Round #756 (Div. 3)

文章目录刷题之Codeforces Round #756 (Div. 3)[1611A]. Make Even[1611B]. Team Composition: Programmers and Mathematicians[1611C]. Polycarp Recovers the Permutation[1611D]. Weights Assignment For Tree Edges[1611E1]. Escape The Maze (easy version)[1611E2]. Escape The

xxayt的博客 342

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Codeforces Round #222 (Div. 2) 题解

A.Playing with Dice 题意:输入ab,问1~6中有几个数离a近,几个数距离ab相等,几个数离b近 思路:直接暴力答案 代码: #include <bits/stdc++.h>using namespace std; int main() { int a,b; scanf("%d%d", &a, &b); ...

weixin_30246221的博客 195

1、Codeforces Round #222 (Div. 2)

A. Playing with Dice 遍历1~6 B. Semifinals 归并排序 C. Maze 题意:给一个地图,问如何覆盖k个格子,让剩下的空格形成一个联通块。 错误思路:找周围最少空位的覆盖,下图就死了。 题解: 找到最大的联通块 bfs/dfs联通块的大小减k大小,这块留空。 除了留空的其他的都覆盖X D. Preparing for the Contest 二分完成的天数d。对BUG和学生的能力进行排序。用学生价格优先队列维护,贪心让能力大于最难的BUG的最便宜的学生..

Mr.chen116的博客 168

Codeforces Round #222 (Div. 2): C. Maze(BFS)

  题意: 给你一个n*m的迷宫,'.'是路,'#'是墙,输入保证所有的'.'构成一个联通块,要求为这个迷宫再添加k面墙,使得剩下所有的'.'仍然构成一个联通块 思路:反过来处理,先将所有的'.'全部变成墙,然后从其中一个'.'开始广搜即可   #include&lt;stdio.h&gt; #include&lt;queue&gt; using namespace std; typ...

加载中... 329

Codeforces Round #222 (Div. 2) ABCD

继续总结做过的CF 比赛链接:http://codeforces.com/contest/378 A Playing with Dice 题意:a,b两个数字,扔一个骰子,求分别与a,b求差的绝对值,谁小就谁赢,相等平局,输出每种情况的个数。 #include #include int a,b; int Dis (int k) { if (fabs(a-k)<fabs(b-k

whyorwhnt的专栏 1210

Codeforces Round #222 (Div. 2) 解题报告

Problem APlaying with Dice 题意:两个人心中都想一个数字,然后掷骰子。骰子1-6问你有几种方案会靠近a想的数字几种一样近几种靠近b的? 思路:大水题一枚直接1-6枚举。 代码如下: 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4...

weixin_34391854的博客 89

寒假训练第十一天-Codeforces Round #222 (Div. 2)

寒假训练第十天-Codeforces Round #221 (Div. 2) 前言:本来说是回过头补一补div3的e f但是我发现那些一二百人过的题我根本没资格去碰它,还是留到假期结束吧,也能检验一下这个寒假到底有多少长进。开始训练div2,尽早稳定三题,冲刺4题。 题目链接-https://codeforces.com/contest/376 A-Playing with Dice 题意:掷骰子,每人给两个数,掷6次,掷的点数离谁给的数谁就赢,输出最终对局情况。 题解:计算掷出的数离谁给的数近即可。 in

Siyue1999的博客 264

视频隐私脱敏工程化:CSRT/KCF追踪算法在本地推理中的实现与边界

在短视频内容合规审查中,动态遮挡(Dynamic Masking)是高频且高耗时的环节。传统手动关键帧打码不仅效率低下,且在目标快速移动或遮挡时极易出现遮罩漂移。本文从计算机视觉工程角度,解析基于CSRT与KCF算法的目标追踪方案在视频隐私处理中的技术路径、性能权衡及落地实践。

Mysssone的博客 185
上一篇: B. Spreadsheets Codeforces Beta Round 1
下一篇: C2. Potions (Hard Version) Codeforces Round 723 (Div. 2)
翰墨织梦
博客等级 码龄4年 384粉丝 84原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值