Pagini recente » Cod sursa (job #677030) | Cod sursa (job #2742726) | Cod sursa (job #1755944) | Cod sursa (job #1145197) | Cod sursa (job #1413943)
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define nmax 310
int N, M, R, C, i, j, mat[nmax][nmax];
double ans, now;
int main()
{
freopen("balans.in", "r", stdin);
freopen("balans.out", "w", stdout);
int i, j, k, l;
scanf("%i %i %i %i", &N, &M, &R, &C);
for(i = 1; i <= N; i++)
for(j = 1; j <= M; j++)
{
scanf("%i", &mat[i][j]);
mat[i + N][j] = mat[i][j + M] = mat[i + N][j + M] = mat[i][j];
}
for(i = 1; i <= 2 * N; i++)
for(j = 1; j <= 2 * M; j++)
mat[i][j] += mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
R = max(R, 1); C = max(C, 1);
for(k = R; k <= N; k++)
for(l = C; l <= M; l++)
for(i = N + 1; i <= 2 * N; i++)
for(j = M + 1; j <= 2 * M; j++)
{
now = mat[i][j] - mat[i - k][j] - mat[i][j - l] + mat[i - k][j - l];
if(now > ans * k * l)
ans = 1.0 * now / (k * l);
}
printf("%.3lf",(int(ans * 1000)) / 1000.0);
return 0;
}