#34534: c++


ericshen0922@gmail.com (little coderrr)

學校 : 不指定學校
編號 : 198722
來源 : [59.115.134.90]
最後登入時間 :
2024-04-18 00:18:34
h027. 202001_2 矩陣總和 -- 2020年1月APCS | From: [101.10.45.213] | 發表日期 : 2023-03-28 00:33

#include<bits/stdc++.h>
using namespace std;

int main() {
    int s,t,n,m,r;
    int su=0,ans1=0,totle=0,totle2=0,sm=9999;
    cin>>s>>t>>n>>m>>r;
    int a[100][100];
    int b[100][100];

    for(int i=0;i<s;++i){
        for(int j=0;j<t;++j){
            cin>>a[i][j];
            totle=totle+a[i][j];
        }
    }

    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>b[i][j];
        }
    }

    for(int i=0;i<n-s+1;++i){
        for(int j=0;j<m-t+1;++j){
            for(int k=0;k<s;++k){
                for(int l=0;l<t;++l){
                    if(b[k+i][l+j]!=a[k][l]){
                        su++;
                    }
                    totle2=totle2+b[k+i][l+j];
                }
            }
            if(su<=r){
                ans1++;
                if(abs(totle2-totle)<=sm){
                    sm=abs(totle2-totle);
                }
            }
            totle2=0;
            su=0;
        }
    }
    if(sm==9999){
        cout<<ans1<<endl<<"-1";
    }


    else{
        cout<<ans1<<endl<<sm;
    }


    return 0;
}

 
ZeroJudge Forum