贪心,如果一个‘*’必须挖掉,则必然存在1个2*2方格,只有它1个'*'
所以用bfs遍历待挖’*‘,注意边界
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<queue>
#include<vector>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (2000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int n,m;
char s[MAXN][MAXN];
int a[MAXN][MAXN]={0};
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int dire[3]={-1,0,1};
bool inside(int i,int j){return (1<=i&&i<=n&&1<=j&&j<=m);}
queue<pair<int,int> > q;
int sum(int i,int j)
{
return a[i][j]+a[i][j+1]+a[i+1][j]+a[i+1][j+1];
}
bool shall_destroy(int i,int j)
{
if (a[i][j]) return 0;
if (sum(i,j)==3||sum(i-1,j)==3||sum(i,j-1)==3||sum(i-1,j-1)==3) return 1;
return 0;
}
int main()
{
// freopen("Walls.in","r",stdin);
scanf("%d%d",&n,&m);
For(i,n)
{
scanf("%s",s[i]+1);
}
For(i,n)
For(j,m) if (s[i][j]=='.') a[i][j]=1;
while(!q.empty()) q.pop();
For(i,n)
For(j,m)
if (shall_destroy(i,j))
{
a[i][j]=1;
q.push(make_pair(i,j));
}
while(!q.empty())
{
pair<int,int> now=q.front();
q.pop();
int x=now.first,y=now.second;
Fork(i,x-1,x+1)
Fork(j,y-1,y+1)
if(inside(i,j)&&shall_destroy(i,j))
{
a[i][j]=1;
q.push(make_pair(i,j));
}
}
For(i,n)
{
For(j,m)
if (a[i][j]) putchar('.');
else putchar('*');
printf("\n");
}
return 0;
}