题库 信息学奥赛题库 题目列表 完善程序 (子矩阵)给输入一个 n1×m1 的矩阵 a,和&n...
组合题

完善程序 (子矩阵)给输入一个 n1×m1 的矩阵 a,和 

n2×m2的矩阵 b,问 a 中是否存在子矩阵和 b 相等。若存在,输出所有子矩阵左上角的坐标:若不存在输出 

There is no answer

There is no 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; }

第 1 题 填空
第 2 题 填空
第 3 题 填空
第 4 题 填空
第 5 题 填空
题目信息
2011年 初赛
-
正确率
0
评论
53
点击