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]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
随机推荐
- java基础41 枚举(类)
1.概述 枚举:一些方法在运行时,它需要数据不能是任意的,而必须是一定范围内的值,可以使用枚举解决 2.枚举的格式 enum 类名{ 枚举值 } 例子 package com.dhb.enumerat ...
- Codeforces 225C Barcode(矩阵上DP)
题目链接:http://codeforces.com/contest/225/problem/C 题目大意: 给出一个矩阵,只有两种字符'.'和'#',问最少修改多少个点才能让每一列的字符一致,且字符 ...
- VS Code折腾记 - (3) 多图解VSCode基础功能
前言 想了想,对于一个刚接触VSCODE的人来说,有什么比图片更通俗易懂的呢? 启动界面 : 快捷键(Ctrl + Shift + E) Search && replace : 快捷键 ...
- 用命令对sql进行备份
利用T-SQL语句,实现数据库的备份与还原的功能 体现了SQL Server中的四个知识点: 1. 获取SQL Server服务器上的默认目录 2. 备份SQL语句的使用 3. 恢复SQL语句的使用, ...
- Python 的內建模块
>>> import __builtin__>>> dir(__builtin__)['ArithmeticError', 'AssertionError', 'A ...
- 使用apt install和使用apt-get install的区别是什么
apt-get是老版的命令,apt是新版的命令,apt还包含了apt-get cache等等,用起来更方便.因为apt刚刚出来,所以允许有apt-get和apt共存,以后apt-get就要淘汰了.
- Newtonsoft.Json 序列化器的重写
public class TestConverter : JsonConverter { public override void WriteJson(JsonWriter writer, objec ...
- C++之客户消费积分管理系统
之前数据结构课程设计要求做这么一个小程序,现在贴上源码,来和大家进行交流学习,希望大家给出意见和建议 程序以链表为主要数据结构对客户信息进行存储,对身份证号码判断了位数及构成(前十七位为数字,最后一位 ...
- 书接前文,用多进程模式实现fibonnachi并发计算
#coding: utf-8 import logging import os import random import sys import time import re # import requ ...
- Delphi IdTCPClient IdTCPServer 点对点传送文件
https://blog.csdn.net/luojianfeng/article/details/53959175 2016年12月31日 23:40:15 阅读数:2295 Delphi ...