F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

3x3 Convolution

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1214    Accepted Submission(s): 569


Problem Description
Given an $n\times n$ matrix $A$ and a $3\times 3$ matrix $K$. These two matrices are very special : they are both non-negative matrices and the sum of all elements in matrix $K$ is 1 (In order to avoid floating-point error, we will give matrix $K$ in a special way in input).

Now we define a function $C(A,K)$, the value of $C(A,K)$ is also a $n\times n$ matrix and it is calculated below(we use $C$ to abbreviate $C(A,K)$):

$C_{x,y}=\sum_{i=1}^{min(n-x+1,3)}\sum_{j=1}^{min(n-y+1,3)}A_{x+i-1,y+j-1}K_{i,j}$

Now we define $C^{m}(A,K)=C(C^{m-1}(A,K),K)$ and $C^{1}(A,K)=C(A,K)$, Kanade wants to know $lim_{t\rightarrow \infty}C^{t}(A,K)$

It's guaranteed that the answer exists and is an integer matrix.
 

Input
There are $T$ test cases in this problem.

The first line has one integer $T$.

Then for every test case:

The first line has one integer $n$.

Then there are $n$ lines and each line has $n$ non negative integers. The j-th integer of the i-th row denotes $A_{i,j}$

Then there are $3$ lines and each line has $3$ non negative integers. The j-th integer of the i-th row denotes $K'_{i,j}$

Then $K$ could be derived from $K'$ by the following formula: $$K_{i,j}=K'_{i,j}/(\sum_{x=1}^{3}\sum_{y=1}^{3}K'_{x,y})$$

$1\leq T\leq 100$

$3\leq n\leq 50$

$0\leq A_{i,j}\leq 1000$

$0\leq K'_{i,j}\leq 1000$

$\sum_{x=1}^{3}\sum_{y=1}^{3}K'_{x,y}>0$
 

Output
For each test case, output the answer matrix by using the same format as the matrix $A$ in input.
 

Sample Input
2 3 1 2 3 4 5 6 7 8 9 3 0 0 0 0 0 0 0 0 3 1 2 3 4 5 6 7 8 9 1 0 0 0 1 0 0 0 0
 

Sample Output
1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-24 21:21:38, Gzip enabled