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

别再对着手册发愁了!手把手教你读懂MIPI-DSI初始化命令(以Rockchip平台为例) 本文深入解析MIPI-DSI初始化命令在Rockchip平台的应用,帮助嵌入式工程师快速掌握LCD屏幕调试技巧。从协议基础到实战指南,详细拆解命令格式、DCS与Generic命令的区别,并提供Rockchip平台的调试全流程与高级技巧,解决常见显示问题。 阅读详情

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.

Sample test(s)
Input
5 5
.*.*.
*****
.*.*.
*****
.*.*.
Output
.*.*.
*****
.*.*.
*****
.*.*.
Input
6 7
***.*.*
..*.*.*
*.*.*.*
*.*.*.*
..*...*
*******
Output
***...*
..*...*
..*...*
..*...*
..*...*
*******
Input
4 5
.....
.....
..***
..*..
Output
.....
.....
.....
.....


用分治的思路……不断扩张扩张……我还是太弱了


就是不断寻找2*2的小方格,方格恰好包括一个星号,

然后把星号变点,再找出因此而满足上述条件的星号,

重复上述条件……


#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
queue<int>qq;
char pic[2010][2010];
int n,m;
bool ok(int i,int j)
{
	if(pic[i][j]=='.')
		return 0;
	if(i-1>=0&&j+1<m&&pic[i-1][j]=='.'&&pic[i-1][j+1]=='.'&&pic[i][j+1]=='.')
		return 1;
	if(i-1>=0&&j-1>=0&&pic[i-1][j]=='.'&&pic[i-1][j-1]=='.'&&pic[i][j-1]=='.')
		return 1;
	if(i+1<n&&j+1<m&&pic[i+1][j]=='.'&&pic[i+1][j+1]=='.'&&pic[i][j+1]=='.')
		return 1;
	if(i+1<n&&j-1>=0&&pic[i+1][j]=='.'&&pic[i+1][j-1]=='.'&&pic[i][j-1]=='.')
		return 1;
	return 0;
}
bool vis[2010][2010];
int tox[8]={-1,-1,0,1,1,1,0,-1};
int toy[8]={0,1,1,1,0,-1,-1,-1};
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%s",pic[i]);
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if(ok(i,j))
			{
				qq.push(i);
				qq.push(j);
				vis[i][j]=1;
			}
	while(qq.size())
	{
		int x=qq.front();qq.pop();
		int y=qq.front();qq.pop();
		pic[x][y]='.';
		for(int i=0;i<8;i++)
		{
			int nx=x+tox[i],ny=y+toy[i];
			if(!vis[nx][ny]&&ok(nx,ny))
			{
				qq.push(nx);
				qq.push(ny);
				vis[nx][ny]=1;
			}
		}
	}
	for(int i=0;i<n;i++)
		puts(pic[i]);
}


空心杯电机在美容仪器中的应用:为什么你的洗脸刷动力这么强? 本文深入解析了空心杯电机如何成为高端美容仪器的核心动力源。通过对比传统电机,揭示了其无铁芯、低惯量、零齿槽效应的技术优势,从而实现了强劲动力、极致静音与细腻震动的用户体验。文章详细阐述了空心杯电机在洁面刷、导入仪等美容仪器中的具体应用与选型考量,并指出了开发中驱动匹配、测试等关键实战要点。 阅读详情

相关推荐

NVIDIA Jetson Orin Nano Super刷机避坑指南:从虚拟机配置到NVMe烧录实战

本文详细介绍了NVIDIA Jetson Orin Nano Super的完整刷机流程,涵盖虚拟机配置、SDK Manager安装、硬件连接、固件下载、rpcbind服务冲突解决以及NVMe烧录等关键步骤。重点解析了Super模式下的NVMe烧录命令参数和操作时机,帮助开发者高效完成刷机并避免常见错误。

y2z3a4b5c的博客 730

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

原题链接:http://codeforces.com/contest/525/problem/D 题意:给了一个矩阵,里面有墙('*')和空地('.'),然后所有空地(边相邻的)都要是矩形 思路:一开始想的是搜索每个点最远的地方,然后果断T了,因为如果后来搜索的矩形包含前面的矩形的话,一个点可以被访问多次,有很多回溯。 然后看了题解。。有个神奇的现象,我们可以观察2*2的方格,如果只有一个'

catfish的专栏 438

制作3D地形图的方法-使用GlobalMapper和3ds Max软件

打开GlobalMapper软件,在菜单栏中选择“文件”>“打开数据文件”,然后选择相应的高程数据文件。在菜单栏中选择“渲染”>“渲染设置”,根据需要进行设置,如分辨率和输出格式。选择地形对象,点击菜单栏中的“渲染”>“材质编辑器”,然后根据需要调整材质属性,如颜色、纹理和光照等。在菜单栏中选择“工具”>“高程栅格和网格”>“创建地形网格”。在菜单栏中选择“文件”>“导出”>“导出栅格格式”。打开3ds Max软件,在菜单栏中选择“文件”>“导入”,然后选择之前导出的地形数据文件。步骤3:导出地形网格。

JqlScala的博客 1501

Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/D Description Finall...

weixin_34138377的博客 113

Codeforces Round #297 (Div. 2) -- D. 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 eno

Never say never 1078

Codeforces Round #297 (Div. 2) 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

GKHack's Blog 843

D. Arthur and WallsCodeforces Round #297 (Div. 2) 搜索(BFS))

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

叶孤心的专栏 624

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

题目地址:Arthur and Walls 这题有一个脑洞,对于当前的点(i,j)并且此点为”*”来说,若存在包含它的2*2正方形中除了它自己外,另外三个点都是”.”,那么这个点就必须要变成”.”。由于去掉这个点之后会对周围的8个点造成影响,所以可以用BFS去搜。WA第12组的应该是只考虑了会影响到周围的4个点了。 代码如下:#include <iostream> #include <strin

scf0920 1449

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

对图广搜,当当前点的一个脚中的通路大于2个,就把他全染成通路,新的通路加入队列。。 #include #include #include #include #include #include #include #include #include #include #include #include #include #define maxn 2005 #define m

yysys 467

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_33712881的博客 130

Codeforces Round #297 (Div. 2) D - Arthur and Walls [思维]【思维】

题目链接:————————————–.————————————–.题目大意 : 就是给你一个n*m的矩阵 里面‘*’代表着墙 ‘.’代表空地 现在让你尽可能少的移开墙 然后使每一片联通的空地都成为一个矩形解题思路: 最开始看到这题的想法就是搜索 判断联通快然后让这一部分所在的最小矩形全部变成‘.’ 然后发现不行 有可能 操作之后的两个矩形又连到一起了,这样的话所有操作都需要再从新来一下,图

Tabris的博客 357

Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs

题目链接:http://codeforces.com/contest/525/problem/D 题意给你一个n*m的田地,有一些*的地方是可以移除变成"."的,然后问你移除最少的"*",使的每一个"."的联通块都是矩形 题解:2*2 的矩形中,如果有一个 '*' 与三个 '.' ,那么这个 '*' 就一定要变成 ‘.' ,然后bfs 代码#include <bits/stdc++.h> using

yxg_123的博客 267

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

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

左眼皮跳跳 787

Codeforces Round #297 (Div. 2) D. Arthur and Walls [ 思维 + bfs ]

传送门 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...

weixin_33779515的博客 116

Codeforces Round #297 (Div. 2) D - 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 eno

lu_1110的博客 309

Codeforces Round #297 (Div. 2) (ABCDE题解)

Codeforces Round #297 (Div. 2) (ABCDE题解)

Tc的专栏 1234
上一篇: ZOJ 3769 Diablo III
下一篇: hdu3966 Aragorn's Story
Last0rder
博客等级 码龄18年 50粉丝 325原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值