题意:问有没有矩形(不能被包含在其他矩形中)相交
其实只要查看四格的正方形中有没有包含3个1,只要有突出的部分,那么在小正方形中一定有3个1
#include<iostream>
using namespace std;
int t,n,m;
char graticule[205][205];
bool fg;
bool check(int i,int j)
{
int cnt=0;
if(graticule[i][j]=='1') cnt++;
if(graticule[i+1][j]=='1') cnt++;
if(graticule[i][j+1]=='1') cnt++;
if(graticule[i+1][j+1]=='1') cnt++;
if(cnt==3) return false;
else return true;
}
int main()
{
cin>>t;
while(t--)
{
cin>>n>>m;
fg=true;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>graticule[i][j];
}
}
for(int i=1;i<n;i++)
{
for(int j=1;j<m;j++)
{
fg=check(i,j);
if(fg==false) break;
}
if(fg==false) break;
}
cout<<(fg==true?"Yes":"No")<<endl;
}
}