codefrces 525 D. Arthur and Walls (bfs-小矩形)

AI处理器组合 编号0-3的处理器处于同一个链路中,编号4-7的处理器处于另外一个链路中,不通链路中的处理器不能通信,如下图所示。- 如果申请处理器个数为1,则选择同一链路,剩余可用的处理器数量为1个的最佳,其次是剩余3个的为次佳,然后是剩余2个,最后是剩余4个。输出为组合列表,当array=[0, 1, 4, 5, 6, 7] ,num=1时,输出为[[0], [1]]- 如果申请处理器个数为2,则选择同一链路剩余可用的处理器数量2个的为最佳,其次是剩余4个,最后是剩余3个。任务申请1个处理器。 阅读详情
D. Arthur and Walls
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Finally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the center of the city with a nice price.

Plan of the apartment found by Arthur looks like a rectangle n × m consisting of squares of size 1 × 1. Each of those squares contains either a wall (such square is denoted by a symbol "*" on the plan) or a free space (such square is denoted on the plan by a symbol ".").

Room in an apartment is a maximal connected area consisting of free squares. Squares are considered adjacent if they share a common side.

The old Arthur dream is to live in an apartment where all rooms are rectangles. He asks you to calculate minimum number of walls you need to remove in order to achieve this goal. After removing a wall from a square it becomes a free square. While removing the walls it is possible that some rooms unite into a single one.

Input

The first line of the input contains two integers n, m (1 ≤ n, m ≤ 2000) denoting the size of the Arthur apartments.

Following n lines each contain m symbols — the plan of the apartment.

If the cell is denoted by a symbol "*" then it contains a wall.

If the cell is denoted by a symbol "." then it this cell is free from walls and also this cell is contained in some of the rooms.

Output

Output n rows each consisting of m symbols that show how the Arthur apartment plan should look like after deleting the minimum number of walls in order to make each room (maximum connected area free from walls) be a rectangle.

If there are several possible answers, output any of them.

Examples
input
5 5
.*.*.
*****
.*.*.
*****
.*.*.
output
.*.*.
*****
.*.*.
*****
.*.*.
input
6 7
***.*.*
..*.*.*
*.*.*.*
*.*.*.*
..*...*
*******
output
***...*
..*...*
..*...*
..*...*
..*...*
*******
input
4 5
.....
.....
..***
..*..
output
.....
.....
.....
.....
题目大意:矩阵'.'代表空地,'*'代表围墙,问怎样去掉最少的围墙使得到最大的矩形空地;
解:别人的想法好好o,把大矩形转为小矩形,那么有四种情况可以成为小矩形:
..   ..
.*   *.

.*   *.
..   ..
用bfs搜索,把符合情况的入队,出队的时候注意判断是否在这之前'*'已经改为'.',
然后出队后,搜索对周围的影响
代码:
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
char map[2010][2010];
int n,m;
int check(int i,int j)
{
	if(map[i][j]=='.'||i<0||i>=n||j<0||j>=m)	return 0;
	if(map[i-1][j-1]=='.'&&map[i-1][j]=='.'&&map[i][j-1]=='.')	return 1;
	if(map[i-1][j]=='.'&&map[i-1][j+1]=='.'&&map[i][j+1]=='.')	return 1;
	if(map[i][j-1]=='.'&&map[i+1][j-1]=='.'&&map[i+1][j]=='.')	return 1;
	if(map[i][j+1]=='.'&&map[i+1][j]=='.'&&map[i+1][j+1]=='.')	return 1;
	return 0;
}
int main()
{
	int i,j;
	scanf("%d%d",&n,&m);	
	queue<pair<int,int> > q;	
	for(i=0;i<n;i++)
	{
		scanf("%s",map[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(check(i,j))
			{
				q.push(make_pair(i,j));//符合小矩形的入队 
			}
		}
	}
	
	while(!q.empty())
	{
		int x=q.front().first;
		int y=q.front().second;
		q.pop();	//出队,并改为'.' 
		if(!check(x,y))	continue;//可能出队前就已经被改过了 
		map[x][y]='.';
		for(i=-2;i<=2;i++)	//改了这个点之后 对周围的点的影响,符合小矩形就入队 
		{
			for(j=-2;j<=2;j++)
			{
				if(i||j&&check(x+i,y+j))	//i||是除check(x,y)之外,因为已经判断过了 
					q.push(make_pair(x+i,y+j));
			}
		}
	}
	for(i=0;i<n;i++)
		printf("%s\n",map[i]);	
	return 0;
}


汽车UDS诊断之诊断会话控制服务(0x10)深度剖析 DiagnosticSessionControl就是诊断会话控制。 请求消息定义 A_Data类型 参数名称 Cvt 字节值 助记符 #1 诊断会话控制请求SID M 0x10 DSC #2 子功能=[诊断会话类型] M 0x00-0xFF LEV_DS_ ... 阅读详情

相关推荐

深度学习动画实战:用MotorNerve系统5步实现自然角色交互

本文详细介绍了如何利用腾讯游戏的MotorNerve系统,通过深度学习技术5步实现自然角色动画交互。从环境搭建、基础运动控制到交互过渡和行走转向优化,该系统能显著提升游戏动画制作效率,尤其适合中小团队替代昂贵的动捕方案。重点解析了骨骼动画配置、PFNN控制器使用及Blender工作流集成等核心技术。

book8的博客 686

【CF】D. Arthur and Walls(BFS + 贪心)

D题 解题思路就是每次检查2X2的方格里是否只有一个‘*’,如果有的话这个*就需要变成‘.’,利用BFS进行遍历,入队的要求是这个点为. 一开始将所有的'.'全部加入队列,如果碰到一个'*'变成'.'就入队,判断的时候从4个方向就行判断 题目链接:http://codeforces.com/contest/525/problem/D #include #include #include #

花月阁 930

AAC编解码器在实时通信中的性能对比与应用选择

本文深入分析了AAC编解码器在实时通信中的性能优化,重点对比了faac、faad2与fdk-aac三大开源方案在WebRTC场景下的表现。通过实测数据揭示其在延迟、音质和资源消耗等关键指标的差异,并提供场景化选型建议与调优技巧,帮助开发者提升实时音视频通信质量。

weixin_29210727的博客 389

Codeforces 525D Arthur and Walls 【Dfs+思维】

D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Finally it is a day when Arthur has eno

mengxiang000000 830

当勒索软件盯上虚拟化层:从CVE-2025-22225漏洞看ESXi安全加固要点

本文深度剖析了针对VMware ESXi虚拟化层的CVE-2025-22225等漏洞链的攻击原理,揭示了攻击者如何利用VMCI、HGFS组件从虚拟机逃逸至宿主机。文章从实战角度出发,系统性地提出了ESXi安全加固的核心策略,包括禁用非必要服务、强化主机配置、实施网络分段、建立实时监控与自动化补丁管理体系,为企业构建纵深防御体系提供了具体可行的操作指南。

terraform7cloud的博客 857

【毕设保姆级指南】基于YOLOv8的DAGM 2007工业缺陷检测系统从搭建到落地

本教程基于YOLOv8算法实现DAGM 2007工业缺陷检测系统,包含数据处理、模型训练和可视化界面开发全流程。首先对DAGM数据集进行格式转换和划分,然后通过YOLOv8训练工业缺陷检测模型,最终构建PyQt5交互界面实现缺陷可视化检测。该系统可用于智能制造中的产品质量控制,帮助快速定位工业产品缺陷,提升检测效率和准确性,为工业质检提供高效解决方案。

LXY_LOVE36的博客 182

Codeforces镜像站( Codeforces.live)

我自己建了一个Codeforces的镜像站,可以打比赛,应该能实现所有国内正常需求 链接直达 发布页面 支持 m1, m2, polygon 服务器在香港和日本 捐助链接

weixin_45538662的博客 1万+

【大语言模型 85】IA3与其他PEFT方法对比

在大语言模型时代,参数高效微调(PEFT)技术成为了降低微调成本的关键。本文深入解析IA3(Infused Adapter by Inhibiting and Amplifying Inner Activations)方法,并与LoRA、AdaLoRA、Prefix Tuning等主流PEFT技术进行全面对比,通过理论分析、代码实现和实验验证,帮助读者理解不同PEFT方法的优劣势和适用场景,为实际项目中的技术选型提供科学依据。

熵数实验室 753

codeforces 525 D Arthur and Walls

codeforces 525 D Arthur and Walls 题意: 给出一个n*m的表格,里面有'*'和'.',求把最少的'*'移除掉,使得'.'所在的连通块是矩形。 限制: 1 思路: 2*2地考虑,如果2*2的格子里只有一个'*',说明这个'*'要去掉,其他情况都不用去掉。然后去掉这个'*'后,又会对其他四个格子有影响。 复杂度好难估计。 /*codefo

whai的专栏 752

蓝桥杯 stm32 PWM 测量频率

参考 数据手册:比赛 的板子 上面有两个信号发生器,如下图。通过 扭动 可变电阻 (R40, R39), 来实现 PWM 频率的改变。PA15PB4。PA15,PB4分别使用TIM2_CH1TIM3_CH1来对频率进行捕获。

wuyiyu_的博客 2931

机器人常用坐标系详解:原理、获取方法及实战实例

本文系统阐述了机器人四大核心坐标系(世界、基、工具、工件)的原理与标定方法。世界坐标系提供全局参考基准,基坐标系绑定机器人本体,工具坐标系定义末端执行器位置,工件坐标系则锁定作业对象位置。通过齐次变换矩阵实现各坐标系间的关联转换。重点介绍了三类标定技术:手动设定法(世界坐标系)、三点/六点法(工具TCP标定)和视觉识别法(工件标定),并以工业机械臂上下料为例演示了完整应用流程。随着技术发展,自动化标定、动态坐标系等新趋势将进一步提升机器人作业精度与效率。

start_up_go的博客 513

D. Arthur and Walls (CF 525 D 搜索bfs)

题意:给出一个n*m的地图,由‘*’和‘.’号组成,现在要将一些'.'改成'*'号使得所有局部的'.'号都能组成一个矩形,要保证修改的次数最少,最后输出改变后的矩形。 思路:最开始的思路是搜联通块,将联通块里面的'*'全部改成‘.’,但是题目范围较大,结果超时了。然后看到别人的是找一个基本元素块,n*m的矩形由这些元素块组成。发现:如果在一个2*2的方格内只有一个是‘*’那么就必须要将这个‘*’改成‘.’,这样bfs搜一遍即可。

@you! 1367

【RT-DETR多模态融合改进】在前期、中期、中后期、后期多模态融合中添加P6大目标检测层,完整步骤及代码

主题: RT-DETR的多模态融合改进中增加P6大目标检测层方式: 分别在前期融合、中期融合、中-后期融合、后期融合中增加P6多模态融合检测层。内容: 包含融合方式详解以及完整配置步骤,开箱即用,一键运行。原始模型结构如下: 二、有效特征层对应的检测头类别 2.1 P3/8 - small检测头 原始模型中的对应的检测头主要用于检测相对较小的目标。其特征图大小相对较大,空间分辨率较高。 适合检测尺寸大概在到像素左右的目标。 2.2 P4/16 - medium检测头 这个检测头对应的经过了更多的下采样

Limiiiing的博客 395

CF525D Arthur and Walls

洛谷 CF 分析 发现在一个边长为 \(2\) 的联通块中,如果只有一个是*,就必须将其改变,然后 \(bfs\) 找就好了。 代码 #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #de...

weixin_30652897的博客 296

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

#297 (div.2) D. Arthur and Walls

1.题目描述:点击打开链接 2.解题思路:本题利用BFS解决。一开始想用dfs去搜索连通块,再想办法找到该连通块的左上角和最大的长,宽,然后把该区域都变成'.',显然这种做法无法处理规模较大的情况。此时应该从分割的思想去考虑。找到一个最基本的元素块,把长方体看做是由这些元素快堆积出来的即可。那么这种元素块应该是什么样的呢? 通过观察不难发现,所有需要变为'.'的点周围肯定都是'.'。换句话说,

Skyline 875

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

codefrces contest 1131 D Gourmet choice(拓扑排序)

链接:http://codeforces.com/contest/1131/problem/D 题意:有n*m个大小关系 d e a &gt; &lt; b &gt; &gt; c = &lt; 表示 a&gt;d,a&lt;e,b&gt;d,b&gt;e,c=d,c&lt;e 找出一种所有数字最小的可行方案 思路:大小...

冰柠橙的博客 230

DFS(思维) CodeForces - 525D Arthur and Walls

D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Finally it is a day when Arthur has enough money for buying a

PiKa__Qiu的博客 468

cf 525D.Arthur and Walls

判断2*2的正方形,是不是3个"."1个"*"然后暴力bfs就好。(这种处理也是挺神奇的2333%%题解) 1 #include<bits/stdc++.h> 2 #define INF 0x7fffffff 3 #define LL long long 4 #define N 100005 5 #define pill pair<int ,int &gt...

weixin_30810239的博客 149

BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls

题目传送门 1 /* 2 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 3 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 4 在2*2的方格里,若只有一个是'*',那么它一定要被替换掉 5 */ 6 #include <cstdio> 7 #include <iostre...

weixin_34358092的博客 144

Codeforces #297( div2) D. Arthur and Walls ( DFS

D. Arthur and WallsDescriptionFinally it is a day when Arthur has enough money for buying an apartment. He found a great option close to the center of the city with a nice price.Plan of the apartment f

Yishui_lovely 372

codeforces 237 C. Primes on Interval

C. Primes on Interval time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You've decided to carry out a survey i

R 1134

codeforces 707 B. Bakery (贪心)

B. Bakery time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Masha wants to open her own bakery and bake muffi

R 959

codeforces 743 B. Chloe and the sequence (规律题)

B. Chloe and the sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Chloe, the same as Vladik, is a co

R 887

codefprces 706C C. Hard problem (动态规划)

C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy is fond of solving different tasks.

R 828

codeforces 74B. Arpa’s obvious problem and Mehrdad’s terrible solution (异或+二分STL)

B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Th

R 731

codeforces 706B B. Interesting drink (二分)

B. Interesting drink time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasiliy likes to rest after a hard wor

R 647

codeforces 444 A. DZY Loves Physics (图的最小密度)

A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY loves Physics, and he enjoys calcul

R 560
上一篇: hdoj 1045 Fire Net (dfs)
下一篇: codeforces 601 A. The Two Routes (最短路d+f)
阿.荣.
博客等级 码龄11年 372粉丝 490原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值