Pagini recente » Cod sursa (job #2762576) | Cod sursa (job #2481838) | Cod sursa (job #213713) | Cod sursa (job #353374) | Cod sursa (job #1204760)
#include <algorithm>
#include <cstdio>
#define MAX_SIZE 305
using namespace std;
static long mat[MAX_SIZE][MAX_SIZE];
int main()
{
int N, M, R, C;
freopen ( "balans.in" , "r" , stdin ) ;
freopen ( "balans.out" , "w" , stdout ) ;
double flMaxBalans = 0.0;
scanf ( "%ld %ld %ld %ld" , &N , &M , &R, &C) ;
if (R == 0)
{
R = 1;
}
if (C == 0)
{
C = 1;
}
for (int i=1; i<=N; ++i)
{
for (int j=1; j<=M; ++j)
{
scanf("%ld", &mat[i][j]);
mat[i+N][j] = mat[i][j];
mat[i][j+M] = mat[i][j];
mat[i+N][j+M] = mat[i][j];
}
}
for (int i=1; i<=2*N; ++i)
{
for (int j=1; j<=2*M; ++j)
{
mat[i][j] = mat[i][j] + mat[i-1][j] + mat[i][j-1] - mat[i-1][j-1];
}
}
for (int r=R; r<=N; ++r)
{
for (int c=C; c<=M; ++c)
{
for (int i=N+1; i<=2*N; ++i)
{
for (int j=M+1; j<=2*M; ++j)
{
long sum = mat[i][j] - mat[i-r][j] - mat[i][j-c] + mat[i-r][j-c];
if (sum > flMaxBalans * r * c)
{
flMaxBalans = (double)sum / (r*c);
}
}
}
}
}
printf("%.3lf", ( long ) ( flMaxBalans * 1000 ) / 1000.0 ) ;
return 0;
}