###题目链接

戳我

\(Solution\)

如果一个#要更改,那么一个四个格子的正方形只有他一个是#,bfs弄一下就好了

\(Code\)

#include<bits/stdc++.h>
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
struct node {
int x,y;
};
queue<node> q;
int n,m;
char a[3001][3001];
int c[3001][3001];
int b[10];
int fx[10]= {0,0,0,1,-1};
int fy[10]= {0,1,-1,0,0};
void bfs() {
while(!q.empty()) {
node now=q.front();
q.pop();
int x=now.x,y=now.y;
b[1]=b[2]=b[3]=b[4]=0;
if(x!=1&&y!=1)
b[1]=c[x-1][y-1]+c[x-1][y]+c[x][y-1];
if(x!=1&&y!=m)
b[2]=c[x-1][y+1]+c[x-1][y]+c[x][y+1];
if(x!=n&&y!=1)
b[3]=c[x+1][y-1]+c[x+1][y]+c[x][y-1];
if(x!=n&&y!=m)
b[4]=c[x+1][y+1]+c[x+1][y]+c[x][y+1];
if(b[1]==1) {
if(c[x-1][y-1]) q.push((node){x-1,y-1}),c[x-1][y-1]=0;
if(c[x-1][y]) q.push((node){x-1,y}),c[x-1][y]=0;
if(c[x][y-1]) q.push((node){x,y-1}),c[x][y-1]=0;
}
if(b[2]==1) {
if(c[x-1][y+1]) q.push((node){x-1,y+1}),c[x-1][y+1]=0;
if(c[x-1][y]) q.push((node){x-1,y}),c[x-1][y]=0;
if(c[x][y+1]) q.push((node){x,y+1}),c[x][y+1]=0;
}
if(b[3]==1) {
if(c[x+1][y-1]) q.push((node){x+1,y-1}),c[x+1][y-1]=0;
if(c[x+1][y]) q.push((node){x+1,y}),c[x+1][y]=0;
if(c[x][y-1]) q.push((node){x,y-1}),c[x][y-1]=0;
}
if(b[4]==1) {
if(c[x+1][y+1]) q.push((node){x+1,y+1}),c[x+1][y+1]=0;
if(c[x+1][y]) q.push((node){x+1,y}),c[x+1][y]=0;
if(c[x][y+1]) q.push((node){x,y+1}),c[x][y+1]=0;
}
}
}
main() {
n=read(),m=read();
for(int i=1; i<=n; i++) {
scanf("%s",a[i]+1);
for(int j=1; j<=m; j++){
if(a[i][j]=='.')
q.push((node) {i,j});
else c[i][j]=1;
}
}
bfs();
for(int i=1;i<=n;i++,cout<<endl)
for(int j=1;j<=m;j++)
if(c[i][j]==1)
cout<<"*";
else cout<<".";
}

最新文章

  1. HTML5学习之智能表单(二)
  2. C# 中的 null
  3. 设计模式_State_状态模式
  4. (hdu 简单题 128道)平方和与立方和(求一个区间的立方和和平方和)
  5. 3D Game Programming withDX11 学习笔记(一) 数学知识总结
  6. 深入解析条件变量(condition variables)
  7. CRM实施目标、需求、策略、厂商、流程等基本介绍全解
  8. okhttputils【 Android 一个改善的okHttp封装库】使用(三)
  9. 初探 Liunx 的命令模式(一)
  10. Python网络爬虫与如何爬取段子的项目实例
  11. 【深度学习与TensorFlow 2.0】卷积神经网络(CNN)
  12. IIS的地址指向
  13. Nacos系列:欢迎来到Nacos的世界!
  14. [转帖]Gartner预测2019年全球IT支出将达到3.8万亿美元
  15. leecode第一百四十一题(环形链表)
  16. kbmMW 5.07.00试用笔记
  17. 【Python】python3 正则爬取网页输出中文乱码解决
  18. Java体验的重点难点-----总结
  19. silent install oracle 11.2.0.1 x86_64 for linux
  20. Elasticsearch5.2.0部署过程的坑

热门文章

  1. c# 获取屏幕图片
  2. Mockito中的@Mock和@Spy如何使用
  3. 养成一个SQL好习惯
  4. mqtt协议实现 java服务端推送功能(一)安装
  5. 微信小程序中button去除默认的边框
  6. js div模拟水平滚动条
  7. css and canvas实现圆形进度条
  8. 内网渗透之frp使用
  9. 第十章、os模块
  10. 网络初级篇之STP(BPDU详解与STP故障恢复)