题面

解析

首先考虑将一个\('*'\)变成\('.'\)后会形成什么,

显然至少是一个\(2\times 2\)的矩形.

因为\(1\times 1\)和\(1\times 2\)的改了没用啊,

而我们考虑什么时候应该把\('*'\)改掉,

对于一个矩形,它可以看成若干个可能重叠的\(2\times 2\)的矩形,

而在一个\(2\times 2\)的矩形中,

如果有三个是\('.'\),一个是\('*'\)的话,这个\('*'\)就要改掉,

要不然是不可能拼成矩形的.

(感性理解下吧...)

所以直接对于每个\('*'\),

判断它需不需要改掉,

在\(dfs\)更新旁边的格子就行了.

(不知道为什么旁边的lzf大仙用\(bfs\)一直T)

code:(代码实现的时候有些巧妙的地方)

#include <iostream>
#include <cstdio>
#include <cstring>
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std; inline int read(){
int sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return f*sum;
} const int N=2005;
int n,m,a[N][N];
int pl,pr,tl,tr;
int que[N*N][3],vis[N][N];
int sta[N*N][3],top;
int dx[5]={-1,0,1,0,-1},dy[5]={0,1,0,-1,0};
char ss[N]; inline void dfs(int x,int y){
if(a[x][y]) return ;
if(x>n||y>m||!x||!y) return ;
for(int k=0;k<4;k++){
int x1=x+dx[k],y1=y+dy[k];
int x2=x+dx[k+1],y2=y+dy[k+1];
int x3=x+(dx[k]?dx[k]:dx[k+1]),y3=y+(dy[k]?dy[k]:dy[k+1]);
if(a[x1][y1]&&a[x2][y2]&&a[x3][y3]){
a[x][y]=1;
for(int i=x-1;i<=x+1;i++)
for(int j=y-1;j<=y+1;j++) dfs(i,j);
return ;
}
}
} int main(){
n=read();m=read();
for(int i=1;i<=n;i++){
cin>>ss;
for(int j=1;j<=m;j++) a[i][j]=(ss[j-1]=='.');
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) dfs(i,j);
}
for(int i=1;i<=n;i++,puts(""))
for(int j=1;j<=m;j++) printf("%c",a[i][j]? '.':'*');
return 0;
}

题解 [CF525D] Arthur and Walls的更多相关文章

  1. 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 ...

  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 ...

  3. 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 ...

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

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

  5. 「CF525D」Arthur and Walls

    题目链接 戳我 \(Solution\) 如果一个#要更改,那么一个四个格子的正方形只有他一个是#,bfs弄一下就好了 \(Code\) #include<bits/stdc++.h> u ...

  6. CodeForces 525D Arthur and Walls

    广搜.看了官方题解才会的..... 定义2*2的小矩阵,有三个是点,一个是星,这样的小矩阵被称为元素块. 首先把所有元素块压入队列,每次取出对头,检查是否还是元素块,如果是 那么将那个*改为点,否则跳 ...

  7. 【Henu ACM Round#18 F】Arthur and Walls

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 考虑,为什么一个连通块里面的空格没有变成一个矩形? 如果不是形成矩形的话. 肯定是因为某个2x2的单张方形里面. 只有一个角是墙.其 ...

  8. cf 525D.Arthur and Walls

    判断2*2的正方形,是不是3个"."1个"*"然后暴力bfs就好.(这种处理也是挺神奇的2333%%题解) #include<bits/stdc++.h& ...

  9. Arthur and Walls CodeForces - 525D (bfs)

    大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...

随机推荐

  1. SQL 十位随机数(大小写字母+数据)

    USE [TEST]GO/****** Object: UserDefinedFunction [dbo].[RANDTENNUMS] Script Date: 2019/7/23 15:40:16 ...

  2. 使用jbc查询数据封装成对象的工具类

    适用于获取Connection对象的util package com.briup.myDataSource; import java.io.FileReader; import java.io.Inp ...

  3. 如何使用RedisTemplate访问Redis数据结构之list

    Redis的List数据结构 这边我们把RedisTemplate序列化方式改回之前的 Jackson2JsonRedisSerializer<Object> jackson2JsonRe ...

  4. Linux系列(15)之进程管理

    详细情况查看:https://www.cnblogs.com/dengyungao/p/8523628.html 1.查看进程 有两个命令可以查看进程,分别是ps与top(推荐使用),那他们有什么区别 ...

  5. thinkphp5.1中使用Bootstrap4分页样式修改

    1.找到thinkphp下的Boorstrap的源码 \thinkphp\library\think\paginator\driver\Bootstrap.php 2丶直接修改源码 <?php ...

  6. springboot+eureka+mybatis+mysql环境下报504 Gateway Time-out

    1.test环境下的数据库配置的 driver和url有问题, 在工程日志中的表现是不能打印出最新的日志,在部署前的日志能看到报错:

  7. [转载]java中import作用详解

    [转载]java中import作用详解 来源: https://blog.csdn.net/qq_25665807/article/details/74747868 这篇博客讲的真的很清楚,这个作者很 ...

  8. 关于Mybatis的几件小事(一)

    一.Mybatis简介 1.Mybatis简介 MyBatis是支持定制化SQL.存储过程以及高级映射的优秀的持久层框架. MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集. M ...

  9. ASP.NET---如何使用web api创建web服务

    1 首先创建asp.net web空项目,并且创建模拟数据,我在工程下面创建了一个Models文件夹,在文件夹Nodels下面创建类Product和Repository 具体如下: [Serializ ...

  10. You are using the runtime-only build of Vue where the template compiler is not available.

    使用vue-cli搭建的项目,启动报错 You are using the runtime-only build of Vue where the template compiler is not a ...