forked from yalza/CPP_code.ptit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPP0271 - LÀM MỊN ẢNH
45 lines (44 loc) · 1.05 KB
/
CPP0271 - LÀM MỊN ẢNH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
using namespace std;
void printSumTricky(int mat[][500], int k,int m,int n)
{
int stripSum[500][500];
for (int j = 0; j < n; j++)
{
int sum = 0;
for (int i = 0; i < k; i++)
sum += mat[i][j];
stripSum[0][j] = sum;
for (int i = 1; i < m - k + 1; i++)
{
sum += (mat[i + k - 1][j] - mat[i - 1][j]);
stripSum[i][j] = sum;
}
}
for (int i = 0; i < m - k + 1; i++)
{
int sum = 0;
for (int j = 0; j < k; j++)
sum += stripSum[i][j];
cout << sum/(k*k) << " ";
for (int j = 1; j < n - k + 1; j++)
{
sum += (stripSum[i][j + k - 1] - stripSum[i][j - 1]);
cout << sum/(k*k) << " ";
}
cout << endl;
}
}
int main() {
int t; cin >> t;
while (t--) {
int m, n, k;
cin >> m >> n >> k;
int M[500][500], N[500][500], X[500][500] = { 0 };
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++)
cin >> M[i][j];
}
printSumTricky(M, k, m, n);
}
}