L形状
2026-02-04 20:40:52
发布于:北京
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=70;
char mp[1100][1100];
vector<int> g[N];
int n,m,cnt;
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};
int vis[N][N];
void dfs(int x,int y){
for(int i=0;i<8;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=1&&ny>=1&&nx<=n&&ny<=m&&vis[nx][ny]==0&&mp[nx][ny]=='*'){
cnt++;
//mp[nx][ny]='.';
vis[nx][ny]=1;
dfs(nx,ny);
}
}
}
bool check(int x,int y){
if(mp[x][y]=='*'&&mp[x+1][y]=='*'&&mp[x+1][y+1]=='*'){
mp[x][y]=mp[x+1][y]=mp[x+1][y+1]='.';
return true;
}
if(mp[x][y]=='*'&&mp[x+1][y]=='*'&&mp[x+1][y-1]=='*'){
mp[x][y]=mp[x+1][y]=mp[x+1][y-1]='.';
return true;
}
if(mp[x][y]=='*'&&mp[x][y+1]=='*'&&mp[x+1][y+1]=='*'){
mp[x][y]=mp[x][y+1]=mp[x+1][y+1]='.';
return true;
}
if(mp[x][y]=='*'&&mp[x+1][y]=='*'&&mp[x][y+1]=='*'){
mp[x][y]=mp[x+1][y]=mp[x][y+1]='.';
return true;
}
return false;
}
void so(){
memset(mp,'.',sizeof mp);
memset(vis,0,sizeof vis);
cin >> n >> m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) cin>>mp[i][j];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]=='*'&&vis[i][j]==0){
vis[i][j]=1;
cnt=1;
dfs(i,j);
if(cnt!=3){
cout<<"NO\n";
return ;
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]=='*'){
if(check(i,j)) continue;
else{
cout<<"NO\n";
return ;
}
}
}
}
cout<<"YES\n";
}
signed main(){
int T;cin>>T;
while(T--){
so();
}
return 0;
}
全部评论 1
撸形状
2026-02-04 来自 重庆
0。?
2026-02-05 来自 北京
0Stars:你这代码我说黄了
2026-02-05 来自 浙江
0

























有帮助,赞一个