题面

解析

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

显然至少是一个\(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. Design Circular Deque

    Design your implementation of the circular double-ended queue (deque). Your implementation should su ...

  2. 杜教BM递推板子

    Berlekamp-Massey 算法用于求解常系数线性递推式 #include<bits/stdc++.h> typedef std::vector<int> VI; typ ...

  3. python 修改文件的创建时间、修改时间、访问时间

    目录 python 修改文件创建.修改.访问时间 方案一 方案二(无法修改文件创建时间) python 修改文件创建.修改.访问时间 突如其来想知道一下 python 如何修改文件的属性(创建.修改. ...

  4. Ubuntu 提示sudo: java: command not found解决办法

    ubuntu下运行sudo Java 时提示“sudo: java: command not found”.在网上找了,其中很多方法都提示要修改/etc/profile的配置,或是修改/etc/env ...

  5. 160个creakme(八)

    peid跑一下,没有壳 就是输入一个码 直接运行一下,出现错误提示 找字符串能找到代码位置 然后看一下401E43的引用,好像跳转指令后面就是注册成功相关字符串 然后nop掉这条指令,发现可以运行出正 ...

  6. 【Trie】Immediate Decodability

    [题目链接]: https://loj.ac/problem/10052 [题意]: 就是给一些串,是否存在两个串是相同前缀的. [题解] 模板题,不想解释了. [代码]: #include<c ...

  7. sonarqube执行命令遇上的小问题

    在安装好sonarqube,本地或是服务器上都是可疑正常运行的情况下. 这一次我重新上传,修改配置SonarQube.Analysis.xml,sonar.host.url的值已经改为服务器上的,执行 ...

  8. Ubuntu18.04通过网线共享网络

    Ubuntu18.04通过网线共享网络 这几天要给实验室一个新电脑装系统,但是实验室路由器好像有点问题,所以决定共享我的笔记本的网络,但是搜了很多教程都是基于Ubuntu16.04的,而Ubuntu1 ...

  9. sketch最强切图工具Sketch Measure

    https://www.inpandora.com/sketch-measure.html https://www.jianshu.com/p/c11ae88e6b1d

  10. 【C++】如何提高Cache的命中率,示例

    参考链接     https://stackoverflow.com/questions/16699247/what-is-a-cache-friendly-code 只是堆积:缓存不友好与缓存友好代 ...