本题暴力判断即可。记得要判边界,而且check的时候铜模的那个位置一定要是1!!!
(┭┮﹏┭┮)(我™就是这个地方gg了,爆蛋啊~ )
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int T,n,m,a,b,d[1010][1010],t[1010][1010];
int x1,y1;
inline int read()
{
int x=0; char c=getchar();
while (c<'0' || c>'9') c=getchar();
while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
bool check(int x,int y)
{
for (int i=1;i<=a;i++)
for (int j=1;j<=b;j++)
{
if ((x+i<=0 || y+j<=0 || x+i>n || y+j>m || !d[x+i][y+j]) && t[i][j]) return 0;
if (t[i][j]) d[x+i][y+j]=0;
}
return 1;
}
int main()
{
T=read();
scanf("%d
",&T);
while (T--)
{
n=read(),m=read(),a=read(),b=read();
scanf("
");x1=y1=0;
for (int i=1;i<=n;i++,scanf("
"))
for (int j=1;j<=m;j++) d[i][j]=(getchar()^48);
for (int i=1;i<=a;i++,scanf("
"))
for (int j=1;j<=b;j++)
{
t[i][j]=(getchar()^48);
if (t[i][j]==1 && !x1) x1=i,y1=j;
}
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if (d[i][j] && !check(i-x1,j-y1)) goto gg;
puts("YES");
continue;
gg:puts("NO");
}
return 0;
}