Pagini recente » Cod sursa (job #332115) | Cod sursa (job #1821246) | Cod sursa (job #703031) | Cod sursa (job #2574814) | Cod sursa (job #918680)
Cod sursa(job #918680)
#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 ) ;
//fstream fout("balans.out", fstream::out);
freopen ( "balans.out" , "w" , stdout ) ;
double flMaxBalans = 0.0;
scanf ( "%ld %ld %ld %ld" , &N , &M , &R, &C) ;
//cout << N << " " << M << " " << R << " " << C << endl;
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)
{
cout << mat[i][j] << " ";
}
cout << endl;
}*/
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];
flMaxBalans = max(flMaxBalans, (double)sum / (r*c));
}
}
}
}
printf("%.3lf", ( long ) ( flMaxBalans * 1000 ) / 1000.0 ) ;
return 0;
}