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