2020 CCPC Network Trials 3x3 Convolution

  • Question meaning
    This question I guess many people are stuck on the question meaning, shit, a lot of formulas. Give an N*N matrix and 3 ∗ 3 3*333 matrix, initially to the3 * 3 * 3 333 The matrix is ​​K', if you want to convert to K, you only need to add the sum of the corresponding elements/matrix elements. Define matrix
    C (A, K) = C (C [A] [K], K) C(A,K)=C(C[A][K],K)C(A,K)=C(C[A][K],K)
    C [ A ] [ K ] C[A][K] C [ A ] [ K ] is calculated as follows: TakeA [i] [j] A[i][j]A [ i ] [ j ] as3 ∗ 3 3*333 The upper left corner of the matrix, expand to the lower right to3 ∗ 3 3*33A matrix of 3 , if it goes out of the boundary, the default is 0. Then this3 ∗ 3 3*33The matrix of 3 and the givenK (3 ∗ 3) K(3*3)K(33 ) , the elements at the corresponding positions are multiplied to find a sum as a newA [i] [j] A[i][j]A [ i ] [ j ] value, traverse each element of A, and do so. In this way, the A matrix has been updated once, so that the matrix A after countless times is obtained.
  • Thinking
    K 'certainly is only one element is not zero, so as to ensure the elements of K and is 1.
    If K is not an element A [1] [1] 1 of, then finally the matrix A is 0, Each operation is equivalent to moving the element in A to the left or up or to the top left, and it will definitely be filled with 0 after countless times.
    If the element that is 1 in K is A[1][1], then A remains unchanged.
  • In addition, the data of this question is out of water, too watery, despite this, post the code.
  • Code
#pragma GCC optimize(2)
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
#define pi acos(-1.0)
#define e exp(1.0)
#define pb push_back
#define mk make_pair
#define fir first
#define sec second
#define scf scanf
#define prf printf
typedef pair<ll,ll> pa;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll MAX_T=120;
const ll MAX_N=50;
ll A[MAX_N][MAX_N],K[4][4],T,N;
int main()
{
    
    
//  freopen(".../.txt","w",stdout);
//  freopen(".../.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin>>T;
	while(T--){
    
    
		ll i,j,k;
		cin>>N;
		for(i=1;i<=N;i++){
    
    
			for(j=1;j<=N;j++)
			cin>>A[i][j];
		}
		ll sum=0,,posx=-1,posy=-1;
		for(i=1;i<=3;i++){
    
    
			for(j=1;j<=3;j++){
    
    
				cin>>K[i][j];
				if(K[i][j]){
    
    
					posx=i;
					posy=j;
				} 
			}
		}
		if(!(posx==1&&posy==1)){
    
    
			for(i=1;i<=N;i++){
    
    
				for(j=1;j<=N;j++){
    
    
					if(j==1)
					cout<<0;
					else
					cout<<' '<<0;
				}
				cout<<endl;
			}
		}
		else{
    
    
			for(i=1;i<=N;i++){
    
    
				for(j=1;j<=N;j++){
    
    
					ll X=i+posx-1;
					ll Y=j+posy-1;
					if(j!=1)
					cout<<' ';
					if(X>N||Y>N)
					cout<<0;
					else
					cout<<A[X][Y];
				}
				cout<<endl;
			}
		}
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_43311695/article/details/108702032