Pagini recente » Cod sursa (job #20834) | Cod sursa (job #2953370) | Cod sursa (job #2300465) | Cod sursa (job #3191620) | Cod sursa (job #918671)
Cod sursa(job #918671)
#include <fstream>
#include <iostream>
#include <cstring>
#include <deque>
#include <algorithm>
#include <numeric>
#include <limits>
#include <iterator>
#define MAX_SIZE 305
using namespace std;
static long long mat[MAX_SIZE][MAX_SIZE];
int main()
{
int N, M, R, C;
fstream fin("balans.in", fstream::in);
fstream fout("balans.out", fstream::out);
double flMaxBalans = 0.0;
fin >> 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)
{
fin >> 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; i<=2*N; ++i)
{
for (int j=M; j<=2*M; ++j)
{
long 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));
}
}
}
}
fout.precision(3);
fout << fixed << flMaxBalans << "\n";
return 0;
}