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 MB
Submit: xxx Solved: 2xx
题目连接
http://codeforces.com/contest/525/problem/D
Description
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 Input
5 5
.*.*.
*****
.*.*.
*****
.*.*.
6 7
***.*.*
..*.*.*
*.*.*.*
*.*.*.*
..*...*
*******
4 5
.....
.....
..***
..*..
Sample Output
.*.*.
*****
.*.*.
*****
.*.*.
***...*
..*...*
..*...*
..*...*
..*...*
*******
.....
.....
.....
.....
HINT
题意:
给你一个n*m的田地,有一些*的地方是可以移除变成"。"的,然后问你移除最少的"*",使的每一个"。"的联通块都是矩形
题解:
爆搜! DFS、BFS、乱搞都能过,只要姿势优美!
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 4001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
string g[maxn];
int n,m;
void check(int x,int y)
{
if(x<||x>=n||y<||y>=m)
return;
int cnt=;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(g[x+i][y+j]=='.')
cnt++;
if(cnt==)
{
for(int i=;i<;i++)
for(int j=;j<;j++)
g[x+i][y+j]='.';
for(int i=-;i<;i++)
for(int j=-;j<;j++)
check(x+i,y+j);
}
return;
}
int main()
{
n=read(),m=read();
for(int i=;i<n;i++)
{
cin>>g[i];
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
check(i,j);
}
}
for(int i=;i<n;i++)
{
cout<<g[i]<<endl;
}
}
Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索的更多相关文章
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...
- 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 stan ...
- 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 ...
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和
Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
随机推荐
- u-boot移植随笔(7):u-boot启动流程简图【转】
转自:http://www.latelee.org/porting-uboot/u-boot-porting-bootstrap.html u-boot移植随笔:u-boot启动流程简图 画上面这张图 ...
- C# 日文网址转punnycode
Uri uri = new Uri(url); IdnMapping idn = new IdnMapping();url= url.Replace(uri.Host, idn.GetAscii(ur ...
- Django 内置模板标签和过滤器
一.内置模板标签 语法:{% %} autoescape : 是否转义,on或off作为参数,并确定自动转义是否在块内有效.该块以endautoescape结束 {% autoescape on % ...
- java基础69 JavaScript产生伪验证码(网页知识)
1.伪验证码 <!doctype html> //软件版本:DW2018版 <html> <head> <meta charset="utf-8&q ...
- java基础50 配置文件类(Properties)
1. 配置文件类Properties的概念 主要生产配置文件与读取配置文件的信息 2.Properties要注意的细节 1.如果配置文件一旦使用了中文,那么在使用store方法生产的配置文件额时候字符 ...
- No.6 selenium学习之路之下拉框Select
HTML中,标签显示为select,有option下拉属性的为Select弹框 1.Xpath定位 Xpath语法,顺序是从1开始,编程语言中是0开始
- Android studio 安装过程中遇到的问题
之前用eclipse,想换下studio试试,安装时遇到问题,参考:http://www.cnblogs.com/csulennon/p/4178404.html
- MySQL学习笔记:创建整年日期
见识到另外一种创意,惊讶! 1.创建小数据表 0-9 # 创建小数据表 DROP TABLE IF EXISTS aa_numbers_small; CREATE TABLE aa_numbers_s ...
- 如何用python解析mysqldump文件
一.前言 最近在做离线数据导入HBase项目,涉及将存储在Mysql中的历史数据通过bulkload的方式导入HBase.由于源数据已经不在DB中,而是以文件形式存储在机器磁盘,此文件是mysqldu ...
- 1497: [NOI2006]最大获利
新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在新一代通讯技术血战的前夜,需要做太多的准备工作,仅就站址选择一项,就需要完成前期市场研 ...