Pagini recente » Cod sursa (job #3268354) | Cod sursa (job #1316380) | Cod sursa (job #1558886) | Cod sursa (job #413807) | Cod sursa (job #2638788)
#include <bits/stdc++.h>
using namespace std;
int N, M, R, C;
int a[301][301];
long long sp[301][301];
double sol = -1;
int main()
{
freopen("balans.in","r",stdin);
freopen("balans.out","w",stdout);
scanf("%d%d%d%d",&N,&M,&R,&C);
for (int i = 1; i <= N; ++ i ) {
for (int j = 1; j <= M; ++ j ){
scanf("%d", &a[ i ][ j ]);
a[ i + N ][ j ] = a[ i ][ j ];
a[ i ][ j + M ] = a[ i ][ j ];
a[ i + N ][ j + M ] = a[ i ][ j ];
}
}
N *= 2, M *= 2;
for (int i = 1; i <= N; ++ i ) {
for (int j = 1; j <= M; ++ j ) {
sp[ i ][ j ] = (sp[ i - 1 ][ j ] + sp[ i ][ j - 1 ] - sp[ i - 1 ][ j - 1 ] + a[ i ][ j ]);
}
}
for (int r = R; r <= N / 2; ++ r ) {
for (int c = C; c <= M / 2; ++ c ) {
int Max = 0;
for (int i = N / 2 + 1; i <= N; ++ i ) {
for (int j = M / 2 + 1; j <= M; ++ j ) {
int sum = sp[ i ][ j ] - sp[ i - r ][ j ] - sp[ i ][ j - c ] + sp[ i - r ][ j - c ];
if (sum > Max) {
Max = sum;
}
}
}
double rez = (double)Max / (r * c);
if (rez > sol) {
sol = rez;
}
}
}
printf("%.3f\n", sol - 0.000499);
return 0;
}