黑白方块
2026-11-22 14:35:36
发布于:广东
1阅读
0回复
0点赞
模拟算法
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)//处理t轮
{
char a[105][105];//最好用字符数组
int n,m;
bool flag=false;//标志是否存在
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];//输入
}
}
for(int i=1;i<=n-3;i++)
{
for(int j=1;j<=m-3;j++)
{
if(a[i][j]=='0'&&a[i][j+1]=='0'&&//第一行满足条件0000
a[i][j+2]=='0'&&a[i][j+3]=='0')
{
if(a[i+1][j]=='0'&&a[i+1][j+1]=='1'&&第二行满足条件0110
a[i+1][j+2]=='1'&&a[i+1][j+3]=='0')
{
if(a[i+2][j]=='0'&&a[i+2][j+1]=='1'&&第三行满足条件0110
a[i+2][j+2]=='1'&&a[i+2][j+3]=='0')
{
if(a[i+3][j]=='0'&&a[i+3][j+1]=='0'&&第四行满足条件0000
a[i+3][j+2]=='0'&&a[i+3][j+3]=='0')
{
flag=true;//找到了
}
}
}
}
}
}
if(flag==true)//如果找到了
{
cout<<"Yes"<<endl;//输出 Yes
}
else//没找到
{
cout<<"No"<<endl;//否则输出 No
}
}
return 0;
}
这里空空如也






有帮助,赞一个