#111. NOIP2011PJ-27
NOIP2011PJ-27
27.(完善程序)
(子矩阵)给输入一个 n1 × m1 的矩阵 a,和 n2 × m2 的矩阵 b,问 a 中是否存在子矩阵和 b 相等。若存在,输出所有子矩阵左上角的坐标:若不存在输出 “There isno answer”。
#include<iostream>
using namespace std;
const int SIZE = 50;
int n1,m1,n2,m2,a[SIZE][SIZE],b[SIZE][SIZE];
int main()
{
int i,j,k1,k2;
bool good ,haveAns;
cin>>n1>>m1;
for(i=1;i<=n1;i++)
for(j=1;j<=m1;j++)
cin>>a[i][j];
cin>>n2>>m2;
for(i=1;i<=n2;i++)
for(j=1;j<=m2;j++)
_________________________;
haveAns=false;
for(i=1;i<=n1-n2+1;i++)
for(j=1;j<=_________________________;j++){
_________________________;
for(k1=1;k1<=n2;k1++)
for(k2=1;k2<=_________________________;k2++){
if(a[i+k1-1][j+k2-1]!=b[k1][k2])
good=false;
}
if(good){
cout<<i<<' '<<j<<endl;
_________________________;
}
}
if(!haveAns)
cout<<"There is no answer"<<endl;
return 0;
}
①:{{ input(1) }}
②:{{ input(2) }}
③:{{ input(3) }}
④:{{ input(4) }}
⑤:{{ input(5) }}